This file upload implementation can be used for instance application development, because of the better security restrictions, of course, you can also upload image file type to get a judge.
Today, the next few sites to improve the file upload system, by the way to send something.
Full PHP code, no JS, file type according to the suffix name, non-MIME judgment.
Create a new up.php with the following code:
The code is as follows |
Copy Code |
$uptype =array ("jar", "zip"); Allow file types to be uploaded $max _file_size=20480000; Upload file size limit, unit byte $path _parts=pathinfo ($_server[' php_self '); Get current path $destination _folder= "files/"; Upload file path $name = "Muxi_". Date ("Y-m-d_h-i-s"); Save file name if ($_server[' request_method '] = = ' POST ') { $file = $_files["Upload_file"]; if (!is_uploaded_file ($file ["Tmp_name"])) Whether the file exists { echo "file does not exist! "; Exit } $torrent = Explode (".", $file ["name"]); $fileend = End ($torrent); $fileend = Strtolower ($fileend); if (!in_array ($fileend, $uptype)) Check the upload file type { echo "does not allow uploading this type of file! "; Exit } if ($max _file_size < $file ["size"]) Check File size { echo "File is too large to exceed the upload limit! "; Exit } if (!file_exists ($destination _folder)) mkdir ($destination _folder); $filename = $file ["Tmp_name"]; $image _size = getimagesize ($filename); $pinfo =pathinfo ($file ["name"]); $ftype = $pinfo [extension]; $destination = $destination _folder. $name. ".". $ftype; if (file_exists ($destination) && $overwrite! = True) { echo "file with the same name already exists! "; Exit } if (!move_uploaded_file ($filename, $destination)) { echo "Error moving File! "; Exit } $pinfo =pathinfo ($destination); $fname = $pinfo [basename]; echo "uploaded successfully! "; } ?> |
Calling code:
The code is as follows |
Copy Code |
|
With the MIME type limit has the limitation, some files in the upload is not the normal itself mime, causes the upload to be unsuccessful, but with the suffix name restriction can solve this problem very well.
http://www.bkjia.com/PHPjc/632755.html www.bkjia.com true http://www.bkjia.com/PHPjc/632755.html techarticle This file upload implementation can be used for instance application development, because of the better security restrictions, of course, you can also upload image file type to get a judge. Change Today ...