PHP File Upload Instance code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code echo file file upload filesize html name php

?
if (! $UploadAction):
?>

<HTML>
<HEAD>
<TITLE> File Upload Interface </TITLE>
</HEAD>
<BODY>

<table>
<TR align= "center" >
<td><form enctype= "Multipart/form-data" name= "SubmitForm" action= "upload.php Tutorial" METHOD= "POST" >
<input type= "hidden" name= "max_file_size" value= "1000000" ><input "type=" hidden "name=" Uploadaction "value=" 1 ">
</td></tr>
<TR align= "center" >
<td><input name= "UploadFile" type= "file" size= "></td>"
</tr>
<TR align= "center" >
<td><input name= "Submit" value= "submitted www.jzread.com" type= "Submit" ></td>
<td><input name= "reset" value= "reset" type= "reset" ></td>
</tr>
</form>
</table>
</center>
</BODY>
</HTML>

?
Else:
?>

<HTML>
<HEAD>
<TITLE> File Upload Code </TITLE>
</HEAD>
<BODY>
?
$UploadAction = 0;
echo "good!";
$TimeLimit = 60; /* Set timeout limit time of 30 seconds set to 0 when unlimited * *
Set_time_limit ($TimeLimit);

If ($UploadFile!= "None")
{
$UploadPath =addslashes (dirname ($PATH _translated)). " Www.jzread.com "; Upload File Store path

$FileName = $UploadPath. $UploadFile _name; Upload file name

    if ($UploadFile _size < 1024)//upload file size
    {
  $FileSize = (string) $ Uploadfile_size. "bytes"; 
 
     elseif ($UploadFile _size < (1024 * 1024))
     {
  $FileSize =number_format (double) ($UploadFile _size/1024), 1. "KB";
    }
  else{
  $FileSize =number_format (double) ($UploadFile _size/(1024 * 1024)), 1). "MB";
    }
   
    if (!file_exists ($FileName))
    {
          if (copy ($UploadFile, $FileName))
          {  echo "File $UploadFile _name ($FileSize) uploaded successfully! "; }
         Else
         { echo "File $UploadFile _name upload failed! "; }

Unlink ($UploadFile);
}
Else
{echo file $UploadFile _name already exists! "; }
}
Else
{echo "You didn't choose any file upload!" "; }

Set_time_limit (30); Restore default timeout settings

?>

<br><a HREF = "upload.php" > Return </A>

</BODY>
</HTML>
?
endif;
?>

Related Article

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.