A brief introduction to the principle of php file upload

怪我咯
Release: 2023-03-12 17:40:01
Original
2305 people have browsed it

PHP file uploadThe principle is simply analyzed. Friends who learn PHP can refer to it. It is indeed much simpler than asp.

//Form uploads can only use the multipart/form-data encoding format
$_FILES system Function ;
$_FILES['myFile']['name'] file Name
$_FILES['myFile']['type']The type of file, restricted by the server
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 to the service
$_FILES['myFile'][ 'error'] Error code;
0 Success 1 Exceeds the php.ini size 2 Exceeds the value specified by the MAX_FILE_SIZE option
3 Only partially uploaded 5 The uploaded file size is 0

move_uploaded_file(temporary file, target location and file name);
Function to move the file to the target location after uploading
is_uploaded_file(MIME);
Function to determine the uploaded MIME type of the file

The code is as follows:

<form enctyoe="multipart/form-data" method="post" name="upload"> 
<input name="upfile" name="name"> 
</form> 
if(is_uploaded_file($_FILES[&#39;myFile&#39;][&#39;tmp_name&#39;])){ 
$upfile = $_FILES[&#39;upload&#39;]; 
$name = $upfile[&#39;name&#39;]; 
$type = $upfile[&#39;type&#39;]; 
$size = $upfile[&#39;size&#39;]; 
$tmp_name = $upfile[&#39;tmp_name&#39;]; 
$error = $upfile[&#39;error&#39;]; 
switch($type){ 
case &#39;image/pjpeg&#39; : $ok=1; 
break 
} 
if($ok){ 
move_uploaded_file($tmp_name,&#39;up/&#39;.$name); 
}else{ 
echo "文件类型不允许"; 
} 
}
Copy after login


The above is the detailed content of A brief introduction to the principle of php file upload. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!