Php implements code for uploading Image files

Source: Internet
Author: User
In PHP program development, file upload is a very common function and a required skill for PHP programmers. It is worth noting that implementing the file upload function in PHP is much simpler than in Java, C #, and other languages. Next we will introduce in detail how to use PHP to implement file upload and multifile Upload functions based on specific code examples. The code is very simple. here we will not talk nonsense, and we will provide the source code directly.

<? Php // name of the registry ticket $ name = ""; $ nameErr = ""; if ($ _ SERVER ["REQUEST_METHOD"] = "POST ") {if (empty ($ _ POST ['name']) {} else {$ name = $ _ POST ['name']; if (! Preg_match ("/^ [a-zA-Z] * $/", $ name) {$ nameErr = "only letters and spaces are allowed ";} else {echo 'name '. $ name ;}// file upload if ($ _ FILES ["file"] ["type"] = "image/gif ") | ($ _ FILES ["file"] ["type"] = "image/jpeg ") | ($ _ FILES ["file"] ["type"] = "image/pjpeg ")) & ($ _ FILES ["file"] ["size"] <2000000) {if ($ _ FILES ["file"] ["error"]> 0) {echo "error :". $ _ FILES ["file"] ["error"]."
";} Else {echo" upload: ". $ _ FILES [" file "] [" name "]."
"; Echo" type: ". $ _ FILES [" file "] [" type "]."
"; Echo" size: ". $ _ FILES [" file "] [" size "]."
"; Echo" stored in :". $ _ FILES ["file"] ["tmp_name"] ;}} else {if (file_exists ("weiwei /". $ _ FILES ["file"] ["name"]) {echo $ _ FILES ["file"] ["name"]. "Upload successful. ";} else {move_uploaded_file ($ _ FILES [" file "] [" tmp_name "]," weiwei /". $ _ FILES ["file"] ["name"]); echo "Stored in :". "weiwei /". $ _ FILES ["file"] ["name"];} echo "uploaded" ;}}?> Registry ticket

The above is all the content of this article. I hope you will like it.

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.