Php-file upload function,
Php-file upload function
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 // get the file information $ arr = $ _ FILES ["file"]; // var_dump ($ arr); // Add constraints // 1. file Type // 2. file Size // 3. if ($ arr ["type"] = "image/jpeg" | $ arr ["type"] = "image/png ") & $ arr ["size"] <10241000) {// path of the temporary file $ arr ["tmp_name"]; // The location where the uploaded file is stored // avoid File Duplication: // 1. timestamp. time () and user name. $ uid or add. date ('ymdhis ') // 2. like a network disk, use folders to prevent duplication $ filename = ". /images /". date ('ymdhis '). $ arr ["name"]; // determine whether the file exists before saving if (file_exists ($ filename) {echo "the file already exists ";} else {// there is a problem with the Chinese name file, so you need to convert the encoding format $ filename = iconv ("UTF-8", "gb2312", $ filename ); // move the temporary file to the location where the uploaded file is stored(Core code)// In brackets: 1. path of the temporary file, 2. storage path move_uploaded_file ($ arr ["tmp_name"], $ filename) ;}} else {echo "the size or type of the uploaded file does not match ";}