AJAX php No refresh upload picture Instance Code _php tutorial

Source: Internet
Author: User
Tags php form
We would have done it before. ajax+php implementation file upload, so that users do not refresh the page is a dynamic upload of images, improve the user experience, then use the most is using the IFRAME to operate, below I introduce the real Ajax PHP image upload instance.


have been studying the ajax+php form without refresh verification, mainly used in the registration submission form above, the use of Ajax technology to make visitors more friendly to the Web page, as the most important technology to improve page-friendliness, Ajax is essential.

Of course, Ajax is not only the form of non-refresh verification, but also can be better applied to the other parts of the page, where there is no refresh of the place basically has Ajax technology figure, today's discussion is ajax+php no refresh upload image.

No refresh upload pictures of the technology is often used in uploading attachments or images upload, such as the common QQ mailbox upload attachments, 163 mailbox upload attachments, QQ space upload pictures, such as the application of Ajax No refresh technology, you can let us in the current page to see uploaded attachments, and in the general small site backstage, upload products , often do not see the picture of the product upload, this often does not have a good effect.

Below is a ajax+php of the non-refresh upload image source code, this is just an instance, and modify this instance can be very well applied in the Web page, for your page to add a non-refresh image upload effect bar, such a lot of effect, you can go to the Internet to find.

file.php file

The code is as follows Copy Code





<title>Untitled Document</title>


$sort = 12;
$f _type=strtolower ("swf,jpg,rar,zip,7z,iso,gif");//Set the type of file that can be uploaded
$file _size_max=200*1024*1024;//limit the maximum capacity of a single file upload
$overwrite = 0;//is allowed to overwrite the same file, 1: Allowed, 0: not allowed
$f _input= "Files";//Set up an upload domain name
foreach ($_files[$f _input]["error"] as $key = = $error) {
$up _error= "No";
if ($error = = UPLOAD_ERR_OK) {
$f _name=$_files[$f _input][' name ' [$key];//get the upload source file name

$uploadfile = $uploaddir. Strtolower (basename ($f _name));

$tmp _type=substr (STRRCHR ($f _name, "."), 1);//Get the file name extension
$tmp _type=strtolower ($tmp _type);
if (!stristr ($f _type, $tmp _type)) {
echo "";
$up _error= "yes";
}

if ($_files[$f _input][' size '] [$key]> $file _size_max) {

echo "";
$up _error= "yes";
}

if (file_exists ($uploadfile) &&! $overwrite) {
echo "";
$up _error= "yes";
}
$string = ' abcdefghijklmnopgrstuvwxyz0123456789 ';
$rand = ";
for ($x =0; $x <12; $x + +)
$rand. = substr ($string, Mt_rand (0,strlen ($string)-1), 1);
$t =date ("Ymdhis"). substr ($gettime [0],2,6). $rand;
$attdir = "./file/";
if (!is_dir ($attdir))
{mkdir ($attdir);}
$uploadfile = $attdir. $t. ".". $tmp _type;
if ($up _error!= "yes") and (Move_uploaded_file ($_files[$f _input][' tmp_name ')

[$key], $uploadfile))) {


$_msg=$_msg. $f _name. ' Upload success n ';


}
else{
$_msg=$_msg. $f _name. ' Upload failed n ';
}
}

}
echo "";
?>

Fileupload.htm page

The code is as follows Copy Code





<title>No refresh File upload system</title>






http://www.bkjia.com/PHPjc/632815.html www.bkjia.com true http://www.bkjia.com/PHPjc/632815.html techarticle we used to do it. ajax+php implement file upload, so that users do not refresh the page is a dynamic upload of images, improve the user experience, then the most used is to use the IFRAME to operate ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.