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";}