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.