The legendary...File upload_PHP tutorial

WBOY
Release: 2016-07-14 10:07:20
Original
1063 people have browsed it

Image upload in file upload

First, set the format, size (MAX_size), and attributes (type) of the image.

Then use logic to judge.

Finally, create a

form and upload it.

Source code:

file.php

print_r($_FILES);
define('MAX_SIZE',100000);
$arr_filetype = array('image/jpeg','image/pjpeg','image/png','image/x-png','image/gif','application/octet-stream');
if ($_FILES["file"]["error"]>0){
echo "Failed to upload file!";
}

else {
if(!in_array($_FILES["file"]["type"],$arr_filetype)){
echo "<script>alert('The file format is incorrect! Please re-upload!');history.back();</script>";
exit;
}

/*switch($_FILES["file"]["type"]){
case 'image/jpeg':break;
case 'image/pjpeg':break;
case 'image/gif':break;
case 'image/png':break;
case 'image/x-png':break;
default:echo "<script>alert('The file format is incorrect! Please re-upload!');history.back();</script>";

       } */                                                         else{
if($_FILES["file"]["size"]>100000){
echo "<script>alert('The file is too large! Please re-upload!');history.back();</script>";
exit;
}  
}
if(move_uploaded_file($_FILES["file"]["tmp_name"],"d:/wamp/tmp/".time().$_FILES["file"]["name"])){
echo "File uploaded successfully!";
}
}


?>

file.html

Upload image



http://www.bkjia.com/PHPjc/477881.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477881.htmlTechArticleWhen uploading images in file upload, you must first set the format, size (MAX_size), and attributes (type) of the image. Then use logic to judge. Finally, create a form/form form and upload it. ...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template