File transfer software php file upload instance code

Source: Internet
Author: User
Tags php file upload
Project Structure:

Upload homepage:

Upload effect:


fileupload.php

Copy the Code code as follows:



Print_r ($_files["Upfile"]);
if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {
$upfile =$_files["Upfile"];
Gets the value inside the array
$name = $upfile ["name"];//the filename of the uploaded file
$type = $upfile ["type"];//types of uploaded files
$size = $upfile ["Size"];//upload files
$tmp _name= $upfile ["Tmp_name"];//the temporary storage path of the uploaded file
Determine if it is a picture
Switch ($type) {
Case ' image/pjpeg ': $okType =true;
Break
Case ' image/jpeg ': $okType =true;
Break
Case ' image/gif ': $okType =true;
Break
Case ' image/png ': $okType =true;
Break
}
if ($okType) {
/**
* 0: File Upload successful

* 1: exceeds the file size, set in the php.ini file

* 2: The size of the file exceeds the value specified by the max_file_size option

* 3: Files are only partially uploaded

* 4: No files are uploaded

* 5: Upload file size is 0
*/
$error = $upfile ["Error"];//the value returned by the system after uploading
echo "================
";
echo "Upload file name is:". $name. "
";
echo "Upload file type is:". $type. "
";
echo "Upload file size is:". $size. "
";
echo "The value returned by the system after uploading is:". $error. "
";
echo "The temporary storage path for uploading files is:". $tmp _name. "
";
echo "Start moving the upload file
";
Move the uploaded temporary files to the up directory
Move_uploaded_file ($tmp _name, ' up/'. $name);
$destination = "up/". $name;
echo "================
";
echo "Upload message:
";
if ($error ==0) {
echo "File Upload succeeded! ";
echo "
Picture preview:
";
echo "";
echo "alt=\" Picture preview: \ r file name: ". $destination." \ r upload time: \ ">";
}elseif ($error ==1) {
echo "Exceeds file size, set in php.ini file";
}elseif ($error ==2) {
echo "exceeded the file size max_file_size option specified value";
}elseif ($error ==3) {
echo "file is only partially uploaded";
}elseif ($error ==4) {
echo "No files were uploaded";
}else{
echo "Upload file size is 0";
}
}else{
echo "Please upload pictures in jpg,gif,png and other formats!" ";
}
}
?>


In the fileupload.php file:

Copy the Code code as follows:


Determine if it is a picture
Switch ($type) {
Case ' image/pjpeg ': $okType =true;
Break
Case ' image/jpeg ': $okType =true;
Break
Case ' image/gif ': $okType =true;
Break
Case ' image/png ': $okType =true;
Break
}


Above is to determine whether the file is a picture type, more file types, you can refer to the Tomcat/conf/web.xml file, the file type is very full ....

The above describes the file transfer software php file upload instance code, including the file transfer software content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.