file.php file
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//Set the file types that can be uploaded
$file_size_max=200*1024*1024;//Limit the maximum capacity of a single file upload
$overwrite = 0;//Whether it is allowed to overwrite the same file, 1: allowed, 0: not allowed
$f_input="files";//Set the 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 extension
$tmp_type=strtolower($tmp_type);
If(!stristr($f_type,$tmp_type)){
echo "<script>alert('Sorry, cannot upload ".$tmp_type." format file, ".$f_name." file upload failed!')</script>";
$up_error="yes";
If ($_files[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('Sorry, the file you uploaded ".$f_name." has a capacity of ".round($_files[$f_input]<br>
['size'][$key]/1024)."kb, greater than the specified".($file_size_max/1024)."kb, upload failed!')</script>";
$up_error="yes";
If (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('Sorry, the file ".$f_name." already exists, upload failed!')</script>";
$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 successful';
}
else{
$_msg=$_msg.$f_name.'Upload failed';
}
}
}
echo "<script>window.parent.finish('".$_msg."');</script>";
/*
For PHP file upload, if Ajax is not used, the effect will not be very good, and the user experience will not be very good. Let’s take a look at this Ajax+PHP file upload code without refreshing.
*/
?>
http://www.bkjia.com/PHPjc/630650.html www.bkjia.com true http: //www.bkjia.com/PHPjc/630650.html TechArticle Uploading php files, if you don’t use ajax to implement it, the effect is not very good, and the user experience is not very good. Okay, let's take a look at this ajax+php no-refresh file upload code. ...
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