File Upload php

Source: Internet
Author: User
Tags upload php

New HTML page a.html

Note: Allowing users to upload files is a huge security risk. Please allow only trusted users to perform file upload operations. <form action= "b.php" method= "POST"   enctype= "Multipart/form-data" >     <label for= "file" >filename: </label><input type= "File" name= "file" id= "file"/> <br/><input type= "Submit" name= "Submit" value = "Submit"/></form></body>New   b.php

By using PHP's global array $_files, you can upload files from a client computer to a remote server.

The first parameter is the input name of the form, and the second subscript can be "name", "type", "Size", "Tmp_name" or "error". Just like this:

$_files["File" ["Name"]-the name of the file being uploaded

$_files["File" ["type"]-the type of file being uploaded

$_files["File" ["Size"]-the size of the uploaded file, measured in bytes

$_files["File" ["Tmp_name"]-the name of the temporary copy of the file stored on the server

$_files["File" ["Error"]-error code caused by file upload

<?php
Determine the file upload type is not more than 20kif ((($_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 "Return Code:". $_files["File" ["Error"]. "<br/>"; } else {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/>"; Determine if the current directory upload (need to be created manually) exists for this file if (file_exists ("upload/". $_files["File" ["Name"])) {echo $_files["file"] [" Name "]. "already exists."; } else {
Does not exist save it in this folder Move_uploaded_file ($_files["file"] ["Tmp_name"], "upload/". $_files["File" ["name"]); echo "Stored in:". " Upload/". $_files["File" ["Name"]; }}}else {echo "Invalid file"; }?>

File Upload php

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.