PHP language-File Upload

Source: Internet
Author: User

1

<body><form action= "chuli.php" method= "post" enctype= "Multipart/form-data" ><input type= "file" Name= " File "/><input type=" submit "value=" Upload "/></form></body>

chuli.php

<?PHP//All information about the uploaded file is saved in $_files["file"; inside the arrayEcho $_files["File"] ["Name"];//Take file nameEcho $_files["File"] ["type"];//Fetch file TypeEcho $_files["File"] ["Size"];//fetch File SizeEcho $_files["File"] ["Tmp_name"];//files are temporarily stored on the server pathEcho $_files["File"] ["Error"];//upload error message//File upload//1. Determine if there is an errorif($_files["File"] ["Error"]){ Echo"Upload Error";}Else{//2. Restrictions on adding conditionsif($_files["File"] ["Type"]== "Image/jpeg" &&$_files["File"] ["Size"]<1024000){//working with file names$str=Date("Ymdhisms", Time());//3. Create a storage path$url= "./img/".$str.$_files["File"] ["Name"];//converts the encoding format of the path to GB to prevent garbled file names$filename=Iconv("UTF-8", "gb2312",$url);if(file_exists($url)){Echo"The file already exists";}Else{//4. StorageMove_uploaded_file($_files["File"] ["Tmp_name"],$url));}}Else{Echo"The type of upload file does not meet the requirements";}}

PHP language-File Upload

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.