PHP basic 22: Upload and save files

Source: Internet
Author: User

<?PHP/*File Upload restrictions && save uploaded files in this script, we added restrictions on file uploads. Users can only upload. gif or. jpeg files, the file size must be less than KB: The above example creates a temporary copy of the uploaded file in the server's PHP Temp folder. This temporary copy of the file disappears at the end of the script. To save the uploaded file, we need to copy it to another location:*/    if((($_files["File"] ["Type"]== "Image/gif") | | ($_files["File"] ["Type"]== "Image/jpeg") | | ($_files["File"] ["type"] = = "Image/pjpeg")) && ($_files["File"] ["Size"] < 20000) ) {        if($_files["File"] ["Error"]>0) {            Echo"Error:".$_files["File"] ["Error"]. " <br/> "; }Else{            //Output Information            Echo"Upload:".$_files["File"] ["Name"]. "<br/>"; Echo"Type:".$_files["File"] ["Type"]. "<br/>"; Echo"Size:". ($_files["File"] ["Size"]/1024). "Kb<br/>"; Echo"Temp file:".$_files["File"] ["Tmp_name"]. "<br/>"; //This example saves the file to a new folder named "Upload".             if(file_exists("upload/".$_files["File"] ["Name"])) {                  Echo $_files["File"] ["Name"]. "already exists."; }Else{                  Move_uploaded_file($_files["File"] ["Tmp_name"], "upload/".$_files["File"] ["Name"]); Echo"Stored in:". Upload/".$_files["File"] ["Name"]; }        }    }Else {        Echo"Invalid file"; }? ><! DOCTYPE html> for= "File" >Filename:</label> <input type= "file" name= "file" id= "file"/> </p> <p> <input type= "Submit" name= "submit" value= "Submit"/> </p> </form></bod Y>

PHP basic 22: Upload and save files

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.