form.php
upload.php
Set the upload file size limit (unit B) $max _size=500000;
Set the file format of the upload file limit $format =array ("Image/jpeg", "Image/gif", "image/png"); File upload directory $dir =dirname (__file__). "
/upload/";
Determine the upload directory, do not exist on the Create if (!is_dir ($dir)) {mkdir ($dir, True);}
Bulk upload file for ($i =0, $j =count ($_files["file"] ["name"]) $i < $j; $i + +) {//uploaded file name $name =$_files["file"] ["name"] [$i];
The type of file being uploaded $type =$_files["file" ["type"] [$i];
The size of the uploaded file, in bytes $size =$_files["File" ["Size"] [$i];
The name of the temporary copy of the file stored on the server $tmp _name=$_files["file" ["Tmp_name"] [$i];
The error code caused by the file upload $error =$_files["file" ["Error"] [$i];
Determine the file size if ($size > $max _size) {exit ("File size exceeds maximum");
}//Judge file format if (!in_array ($type, $format)) {exit ("Invalid file format");
///Generate filename Date_default_timezone_set ("PRC");
$file _name=time (). Mt_rand (1111, 999999);
Gets the file format $ext =substr ($type, Strpos ($type, "/") +1);
if ($error >0) {exit ($error); }else{if (Move_uploaded_file ($tmp _name, $dir. $file_name. "."
$ext)) {//exit ("uploaded success"); }
}
}