Home >Backend Development >PHP Tutorial >PHP Ajax upload file example [ajaxfileupload.js]_PHP tutorial

PHP Ajax upload file example [ajaxfileupload.js]_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:46:54833browse

I have talked about using jquery ajax and php to upload images. Next, I will introduce how to use php ajax to upload various files without refreshing. I will give examples directly and hope it will be helpful to all students.

You can add and upload in batches, which is simple and convenient

The code is as follows Copy code



 


   
       id="file1" size="30" />        onclick="return ajaxFileUpload();" />        style="display: none">UpLoading...

 


 
up_deal.php

 代码如下
 代码如下 复制代码

if ((($_FILES["file1"]["type"] == "image/gif")
|| ($_FILES["file1"]["type"] == "image/jpeg")
|| ($_FILES["file1"]["type"] == "image/bmp")
|| ($_FILES["file1"]["type"] == "image/pjpeg"))
&& ($_FILES["file1"]["size"] < 100000)){//100KB
$extend = explode(".",$_FILES["file1"]["name"]);
$key = count($extend)-1;
$ext = ".".$extend[$key];
$newfile = time().$ext;

if(!file_exists('upload')){mkdir('upload');}
move_uploaded_file($_FILES["file1"]["tmp_name"],"upload/" . $newfile);
@unlink($_FILES['file1']);
echo $newfile;
}else {
echo 'error';
}
?>

复制代码
if ((($_FILES["file1"]["type"] == "image/gif")

|| ($_FILES["file1"]["type"] == "image/jpeg")

|| ($_FILES["file1"]["type"] == "image/bmp") && ($_FILES["file1"]["size"] < 100000)){//100KB     $extend = explode(".",$_FILES["file1"]["name"]);     $key = count($extend)-1;     $ext = ".".$extend[$key];     $newfile = time().$ext;       if(!file_exists('upload')){mkdir('upload');}     move_uploaded_file($_FILES["file1"]["tmp_name"],"upload/" . $newfile);     @unlink($_FILES['file1']);     echo $newfile;
}else {

    echo 'error';
}
?> http://www.bkjia.com/PHPjc/632906.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632906.htmlTechArticle讲过利用jquery ajax与php实现图片上传,下面我介绍利用php ajax实现各种文件无刷新上传,直接放实例希望给各位同学有帮助。 可以批量进行添...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn