PHP file upload sample code
Release: 2016-07-25 08:45:08
Original
1034 people have browsed it
Image upload
Upload file:
//Types that can be uploaded $uptypes=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif ', 'image/bmp','image/x-png'); ?>
The file types allowed to be uploaded are: =implode(',',$uptypes)?>
form>
$max_file_szie=2*pow(2,20); //The uploaded file is less than 2MB $destination_folder='uploadimg/'; // Upload file saving path if($_SERVER['REQUEST_METHOD']=='POST'){ if(!is_uploaded_file($_FILES['upfile']['tmp_name'])){ echo 'The picture does not exist! '; exit; } if($max_file_szie<$_FILES['upfile']['size']){ echo 'The file is too big! '; exit; } if(!in_array($_FILES['upfile']['type'],$uptypes)){ echo 'The file type does not match! '.$_FILES['upfile']['type']; exit; } if(!file_exists($destination_folder)){ mkdir($destination_folder); } $filename=$_FILES['upfile' ]['tmp_name']; $image_size=getimagesize($filename); $pinfo=pathinfo($_FILES['upfile']['name']); //File path information $ftype=$pinfo[' extension']; //Old file extension $destination = $destination_folder.time().".".$ftype; //New file name if(file_exists($destination)&&$voerwrie !=true){ echo 'The file with the same name already exists! '; exit; } //Move the uploaded file from the temporary folder to the specified directory if(!move_uploaded_file($filename,$destination)){ echo 'An error occurred while moving the file! '; exit; } $pinfo=pathinfo($destination); $fname=$pinfo[basename]; echo "Uploaded successfully < br>File name:
".$destination_folder.$fname." ";
echo 'Width:'.$image_size[0];
echo 'Height:'.$image_size[1];
echo ' Size:'.$_FILES['upfile']['size']."bytes";
}
?>
Copy Code
File upload, php
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
Latest Articles by Author
2024-10-22 09:46:29
2024-10-13 13:53:41
2024-10-12 12:15:51
2024-10-11 22:47:31
2024-10-11 19:36:51
2024-10-11 15:50:41
2024-10-11 15:07:41
2024-10-11 14:21:21
2024-10-11 12:59:11
2024-10-11 12:17:31