Php-file upload function,

Source: Internet
Author: User

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

 

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.