PHP File upload function for code sharing

Source: Internet
Author: User
This article mainly introduces the PHP implementation of File Upload function instance code, the code is easy to understand, very good, with reference value, the need for friends can refer to the next

Click Browse to upload the selected files to the created Images folder

The code is as follows:

1.wenjian.php


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

2.chuli.php


<?php//take file information $arr = $_files["File"];//var_dump ($arr);//Plus restrictions//1. File type//2. File size//3. The saved file name does not repeat if (($arr ["type"]== "Image/jpeg" | | $arr ["type"]== "Image/png") && $arr ["Size"]<10241000) {///Temp file path $arr["Tmp_name"];//the location of the uploaded file//Avoid file duplication://1. Timestamp. Time () plus user name. $uid or Add. Date (' Ymdhis ')//2. Similar to a network disk, using folders to prevent duplicate $  filename = "./images/". Date (' Ymdhis '). $arr ["Name"];//before saving to determine if the file exists if (file_exists ($filename)) {echo "The file already exists";  } else {//Chinese name file has problems, so the encoding format needs to be converted $filename = Iconv ("UTF-8", "gb2312", $filename);  Move temporary files to the location where the uploaded files are stored (core code)//in parentheses: 1. The path to the temporary file, 2. The path of the Move_uploaded_file ($arr ["Tmp_name"], $filename); }}else{echo "File size or type of upload does not match";} 

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.