Home > Backend Development > PHP Tutorial > Experience in learning the mass line education and practice activities PHP introductory learning knowledge point 3 PHP upload

Experience in learning the mass line education and practice activities PHP introductory learning knowledge point 3 PHP upload

WBOY
Release: 2016-07-29 08:46:02
Original
988 people have browsed it

1. Upload the HTML code of the form

Copy the code The code is as follows:







Notes : 1. The action is the new one uploaded
   2. The enctype attribute should be written as "multipart/form-data"
2. PHP code

Copy the code The code is as follows:


if(is_uploaded_file ($_FILES["Imgs"]["tmp_name"])){
$phpupfile=$_FILES["Imgs"];
//Output the array structure of the uploaded file;
print_r($phpupfile);
//Output the uploaded file Various information about the 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"]."
"; //The uploaded file name
/*
* Upload error message
* 0 represents successful upload,
* 1, 2 represents exceeded the set maximum upload value
* 3 represents only partial upload
* 4 represents no file uploaded
* 5 represents 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, you need to Move it to the specified folder of the website)
move_uploaded_file($phpupfile["tmp_name"],$phpupfile["name"]); //Save the uploaded file to the specified folder
/*
*The following parts are Additional part
*/
//Judge whether the file exists. 1 means it exists, 0 means it is not found.
echo 'This File is exists:'.file_exists($phpupfile["name"]).'
'; // Query whether the file or directory exists
//unlink Delete file
echo 'Delete file:'.unlink($phpupfile["name"]).';1 means deletion is successful, 0 means deletion failed';
//mkdir Create file Clip
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"]).'
' ;
}
?>


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

The above introduces the experience and experience of learning the mass line education and practice activities. PHP introductory learning knowledge point three PHP upload, including the content of the experience and experience of learning the mass line education and practice activities. I hope it will be helpful to friends who are interested in PHP tutorials.

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