Home >Backend Development >PHP Tutorial >PHP introductory learning knowledge point 3 PHP upload_PHP tutorial

PHP introductory learning knowledge point 3 PHP upload_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:27:05886browse

1. HTML code of the upload form

Copy the code The code is as follows:






Notes: 1. action is new to upload
2. enctype this The attribute should be written as "multipart/form-data"
2. PHP code
Copy code The code is as follows:

< ;?php
if(is_uploaded_file($_FILES["Imgs"]["tmp_name"])){
$phpupfile=$_FILES["Imgs"];
//Output the array structure of the uploaded file ;
print_r($phpupfile);
//Output various information of the uploaded file
echo $phpupfile["size"]."
"; //File name
echo $ phpupfile["type"]."
"; //File type
echo $phpupfile["tmp_name"]."
"; //The file name contains the path yesterday
echo $ phpupfile["name"]."
"; //Uploaded file name
/*
* Upload error message
* 0 means successful upload,
* 1, 2 means Exceeds the set maximum upload value
* 3 means only partial upload
* 4 means no file is uploaded
* 5 means the uploaded file size is 0
*/
echo $phpupfile[ "error"]."
";
//Upload function (after submitting the form, the uploaded file has been saved in the temporary folder of the server. At this time, it needs to be moved to the website In the specified folder)
move_uploaded_file($phpupfile["tmp_name"],$phpupfile["name"]); //Save the uploaded file to the specified folder
/*
*The following part It is an additional part
*/
//Determine whether the file exists. 1 means it exists, 0 means it is not found.
echo 'This File is exists:'.file_exists($phpupfile["name"]).'< ;br>'; //Query whether the file or directory exists
//unlink delete file
echo 'Delete file:'.unlink($phpupfile["name"]).';1 means deletion is successful, 0 Failed to delete';
//mkdir Create folder
if(file_exists('pic')==FALSE){
mkdir("pic");
}
if(file_exists ('pic/ts')==FALSE){
mkdir("pic/ts");
}
//rmdir delete folder
if(file_exists('pic/ts') ==FALSE){
rmdir('pic/ts');
}
//rename Rename
rename("guitar11-hp-sprite.png", "1.png") ;
echo "
";
echo 'This File is exists:'.file_exists($phpupfile["name"]).'
';
}
? >

Note: 1. $_FILES["Imgs"] This Imgs is the name of the control defined in your HTML code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323831.htmlTechArticle1. Copy the HTML code of the upload form. The code is as follows: form action="UpLoad.php" method="post " enctype="multipart/form-data" name="upFrm" input type="file" name="Imgs" id="Imgs"...
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