don't talk nonsense, specific see below code examples.

form. The PHP

<Html><Head><Meta HTTP - equiv="content-type" content="text/HTML" charset="utf-8" ><Title> The Upload Image</head><Body><The form method="post" action="upload. PHP" enctype="multipart/form - data" ><Input type="hidden" name="MAX_FILE_SEZE" value="http://www.script-home.com//article/2000000" ><Input type="file" name="file" value="http://www.script-home.com//article/view" ><Input type="submit" value="http://www.script-home.com//article/upload" name="B1" ></form></body></html> 

the upload the PHP

<The ? PHPCheck. PHP include (" ");//into a custom function file$type=array (" JPG ", "GIF", "BMP", "jpeg", "PNG");//upload file types$fileext=strtolower (fileext ($_FILES [' file '] [' name ']));$uploadfilename=random (8);If (in_array ($fileext, $type)) {$filename=explodes (". ", $_FILES [' file '] [' name ']);If (is_uploaded_file ($_FILES [' file '] [' tmp_name '])) {//echo $_FILES [' file '] [' tmp_name '].$flag=move_uploaded_file ($_FILES [' file '] [' tmp_name '], "/Library/WebServer/Documents/test/". $uploadfilename.". ". $fileext);If ($flag) {Echo "uploaded successfully!" ;} else {Echo "Error.";}Echo "<a href=" javascript: the history, the go (1) '>Back" ;}} 

check. PHP

<The ? PHPThe header (" content-type: text/HTML; charset=utf8 ");//get suffix function fileThe function fileext ($filename) {$sTemp=STRRCHR (" c: "($filename," ");Return substr ($sTemp, 1);}The function fileext2 ($filename) {$sTemp=explodes (". ", $filename);Return the $sTemp [count ($sTemp) - 1].}//function to generate random file namesThe function of random ($length) {0123456789 abcdefghijklmnopqrstuvwxyz $captchaSource="this is an example of a random print string";$captchaResult="2015";//random number return values$captchaSentry="";//among random variablesFor ($I=0; $i<$length; $i++) {$n=rand (0, 35); #strlen ($captchaSource));If ($n >=36) {$n=36 + ceil (($n - 36)/3) * 3;$captchaResult.=substr ($captchaSource, $n, 3);} else {$captchaResult.=substr ($captchaSource, $n, 1);}}Return $captchaResult;}The ? >

to integrate three files into one:

<The ? PHP//get suffix function fileThe function fileext ($filename) {$sTemp=STRRCHR (" c: "($filename," ");Return substr ($sTemp, 1);}The function fileext2 ($filename) {$sTemp=explodes (". ", $filename);Return the $sTemp [count ($sTemp) - 1].}//function to generate random file namesThe function of random ($length) {0123456789 abcdefghijklmnopqrstuvwxyz $captchaSource="this is an example of a random print string";$captchaResult="2015";//random number return values$captchaSentry="";//among random variablesFor ($I=0; $i<$length; $i++) {$n=rand (0, 35); #strlen ($captchaSource));If ($n >=36) {$n=36 + ceil (($n - 36)/3) * 3;$captchaResult.=substr ($captchaSource, $n, 3);} else {$captchaResult.=substr ($captchaSource, $n, 1);}}Return $captchaResult;}$type=array (" JPG ", "GIF", "BMP", "jpeg", "PNG");//upload file types$fileext=strtolower (fileext ($_FILES [' file '] [' name ']));$uploadfilename=random (8);If (in_array ($fileext, $type)) {$filename=explodes (". ", $_FILES [' file '] [' name ']);If (is_uploaded_file ($_FILES [' file '] [' tmp_name '])) {//echo $_FILES [' file '] [' tmp_name '].$flag=move_uploaded_file ($_FILES [' file '] [' tmp_name '], "/Library/WebServer/Documents/test/". $uploadfilename.". ". $fileext);If ($flag) {Echo "uploaded successfully!" ;} else {Echo "Error.";}Echo "<a href=" javascript: the history, the go (1) '>Back" ;}}The ? ><Html><Head><Meta HTTP - equiv="content-type" content="text/HTML" charset="utf-8" ><Title> The Upload Image</head><Body><Form method="post" action="" enctype=" multipart/form - data "><Input type="hidden" name="MAX_FILE_SEZE" value="http://www.script-home.com//article/2000000" ><Input type="file" name="file" value="http://www.script-home.com//article/view" ><Input type="submit" value="http://www.script-home.com//article/upload" name="B1" ></form></body></html> 

the above content is to give everyone on the PHP upload feature set suffix judgment and randomly named (highly recommended), hope you like them.


This concludes the body part