Home >Backend Development >PHP Tutorial >PHP Beginner - PHP File Upload Tutorial_PHP Tutorial

PHP Beginner - PHP File Upload Tutorial_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:09:37923browse

html form upload code



< ;input type="hidden" name="max_file_size" value="100000">
 

The following is the php file upload function code

function uploadfile($type,$name ,$ext,$size,$error,$tmp_name,$targetname,$upload_dir)
{
$max_size = 2000000;
$file_mimes = array('image/pjpeg','image/jpeg' ,'image/jpg','image/gif','image/png');
$file_exts = array('.jpg','.gif','.png','.jpg','. gif','.png');
$file_path = $upload_dir.$targetname;
if(!is_dir($upload_dir))
{
if(!mkdir($upload_dir))
die("The file upload directory does not exist and the file upload directory cannot be created");
if(!chmod($upload_dir,0755))
die("The permissions of the file upload directory cannot be set to readable" Writable");
}
if($size>$max_size)
die("The uploaded file size exceeds the specified size");
if($size == 0)
die("Please select the file to upload");
if(!in_array($type,$file_mimes) || !in_array($ext,$file_exts))
die("Please upload files that meet the requirements Type");
if(!move_uploaded_file($tmp_name, $file_path))
die("Failed to copy file, please upload again");
switch($error)
{
case 0:
return ;
case 1:
die("The uploaded file exceeds the value limited by the upload_max_filesize option in php.ini");
case 2:
die("Upload The size of the file exceeds the value specified by the max_file_size option in the html form");
case 3:
die("Only part of the file was uploaded");
case 4:
die("No file Uploaded");
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444797.htmlTechArticlehtml form upload code form enctype=multipart/form-data action=upload.php tutorial method=post input type= hidden name=max_file_size value=100000 input name=userfile type=file input ty...
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