PHP File Upload Implementation

Source: Internet
Author: User

upload.php

<! DOCTYPE html>


<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<body>
<form action= "doaction.php" method= "post" enctype= "Multipart/form-data" >
Please select the file you want to upload:
<input type= ' file ' name= ' MyFile '/>
<br/>
<input type= "Submit" value= "Upload"/>
</form>


</body>

doaction.php

<?php
Print_r ($_files);
$filename =$_files[' myFile ' [' name '];
$type =$_files[' myFile ' [' type '];
$tmp _name=$_files[' myFile ' [' tmp_name '];
$size =$_files[' myFile ' [' Size '];
$error =$_files[' myFile ' [' Error '];

Remove file
Move_uploaded_file ($tmp _name, $destination);
Move_uploaded_file ($tmp _name, "./". $filename);
Copy ($SRC, $DST)

if ($error = = UPLOAD_ERR_OK)
{
if (Move_uploaded_file ($tmp _name, "./". $filename))
{
echo ' upload success ';
}
Else
{
echo "Upload failed";
}
}
Else
{
Switch ($error)
{
Case 1:
echo "error:1-exceeded the value upload_max_filesize in the php.ini file"

Break
Case 2:
echo "Error:2-the size of the uploaded file exceeds the value of the form max_file_size";
Break
Case 3:
echo "Error:3-file only partially uploaded";
Break
Case 4:
echo "Error:4-no file upload";
Break
Case 6:
echo "Error:6-No temporary folder found";
Break
Case 7:
echo "Error:7-Write Failed";
Break
Case 8:
echo "Error:8--the uploaded file was interrupted by the PHP extension program";
Break
}
}
?>

PHP File Upload Implementation

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.