PHP file upload principle simple analysis

  • 2020-05-05 11:04:25
  • OfStack

// form uploads can only use multipart/ form-data encoding
$_FILES system function;
$_FILES['myFile']['name'] file name
$_FILES['myFile']['type'] file type, server limits
image/**
image/x-png
application/x-zip-compressed
$_FILES['myFile']['size'] upload file size
$_FILES['myFile']['tmp_name'] save the temporary file name
after uploading the service $_FILES['myFile']['error'] error code;
0 success 1 exceeds php.ini size 2 exceeds
as specified by the MAX_FILE_SIZE option 3 only partial upload 5 upload file size 0

move_uploaded_file(temporary file, target location and file name);
The function
that moves the file to the destination after uploading is_uploaded_file(MIME);
Determine the upload MIME type of file function
 
<form enctyoe="multipart/form-data" method="post" name="upload"> 
<input name="upfile" name="name"> 
</form> 
if(is_uploaded_file($_FILES['myFile']['tmp_name'])){ 
$upfile = $_FILES['upload'] ;  
$name = $upfile['name']; 
$type = $upfile['type']; 
$size = $upfile['size']; 
$tmp_name = $upfile['tmp_name']; 
$error = $upfile['error']; 
switch($type){ 
case 'image/pjpeg' : $ok=1; 
break 
} 
if($ok){ 
move_uploaded_file($tmp_name,'up/'.$name); 
}else{ 
echo " File types are not allowed "; 
} 
} 

Related articles: