Introduction of File Upload _php instance via PHP simple example

Source: Internet
Author: User
Tags php file upload temporary file storage
PHP File Upload Simple example, get the file name, type, size and other related information, complete the file upload, for everyone to learn reference.

1, upload the file code:

Code

<?php//determine if the temporary file storage path contains the user uploaded file if (Is_uploaded_file ($_files["UploadFile"] [ "Tmp_name"]) {//In order to be more efficient, store information in a variable $upfile=$_files["UploadFile"];//use an array type string to hold the information of the uploaded file//print_r ($upfile);// If you print, the output is similar to the array ([name] = = m.jpg [Type] = Image/jpeg [Tmp_name] and C:\WINDOWS\Temp\php1A.tmp [ERROR] = 0 [Size] = 44905) $name = $upfile ["Name"];//facilitates the later transfer of the file when the name $type= $upfile ["type"];//the types of uploaded files $size= $upfile ["Size"];// The size of the uploaded file $tmp_name= $upfile ["Tmp_name"];//the temporary name of the user to upload the file $error= $upfile ["Error"];////echo $name during the upload process;//To determine the file type, Determine if you want to transfer the file, if the requirements are set $ok=1 can be transferred switch ($type) {case "image/jpg": $ok =1; break; case "Image/jpeg": $ok =1; /gif ": $ok = 1; Break Default: $ok = 0; break;} If the file meets the requirements and there is no error during the upload process ($ok && $error = = ' 0 ') {//Call Move_uploaded_file () function, file transfer Move_uploaded_file ($tmp _ Name, ' up/'. $name); After the operation is successful, the prompt is successful, echo "";} else{//If the file does not conform to the type or the upload process has errors, the prompt fails echo "";}? 

2. Submit a document form

Code

The above is a small series to share with you through the PHP simple example Introduction file upload, I hope you like.

  • 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.