ajax+php No Refresh File upload Code _php tutorial

Source: Internet
Author: User
Tags php file upload
In the PHP file upload this paragraph, if not Ajax to achieve, the effect is not good, the user experience is not very well, below we will look at this ajax+php no refresh file upload code bar. ajax+php No refresh File upload code

ajax+php Tutorial No Refresh File upload code




<title>ajax+php No refresh File upload code</title>






file.php file

$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
$uploaddir = './www.bkjia.c0m/';
$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 "";
/*
In the PHP file upload this paragraph, if not Ajax to achieve, the effect is not good, the user experience is not very well, below we will look at this ajax+php no refresh file upload code bar.
*/
?>

http://www.bkjia.com/PHPjc/630650.html www.bkjia.com true http://www.bkjia.com/PHPjc/630650.html techarticle in the php file upload this paragraph, if not Ajax to achieve, the effect is not good, the user experience is not very well, below we will look at this ajax+php no refresh file upload code bar. ...

  • 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.