form.php
<HTML><Head> <Metahttp-equiv= "Content-type"content= "text/html"CharSet= "Utf-8"> <title>Upload Image</title></Head><Body><formMethod= "POST"Action= "upload.php"enctype= "Multipart/form-data"> <inputtype= "hidden"name= "Max_file_seze"value= "2000000"> <inputtype= "File"name= "File"value= "View"> <inputtype= "Submit"value= "Upload"name= "B1"></form></Body></HTML>
upload.php
<?PHPinclude("check.php");//Importing Custom Function Files$type=Array("JPG", "gif", "BMP", "JPEG", "PNG");//determine the type of upload file$fileext=Strtolower(Fileext ($_files[' File '] [' Name ']));$uploadfilename= Random (8);if(In_array($fileext,$type)){ $filename=Explode(".",$_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"Upload success!" "; }Else{ Echo"Error."; } Echo"<a href= ' Javascript:history.go ( -1) ' >Back</a>"; }}
check.php
<?PHPHeader("Content-type:text/html;charset=utf8");//get file suffix name functionfunctionFileext ($filename){ $sTemp=STRRCHR($filename, "."); return substr($sTemp, 1);}functionFILEEXT2 ($filename){ $sTemp=Explode(".",$filename); return $sTemp[Count($sTemp)-1];}//generate random file name functionfunctionRandom$length){ $captchaSource= "0123456789abcdefghijklmnopqrstuvwxyz This is an example of a random printout string"; $captchaResult= "2015";//random number return value $captchaSentry= "";//random number Intermediate variable for($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-R); }Else{ $captchaResult.=substr($captchaSource,$n, 1); } } return $captchaResult;}?>
Consolidate three of files into one:
<?PHP//get file suffix name functionfunctionFileext ($filename){ $sTemp=STRRCHR($filename, "."); return substr($sTemp, 1);}functionFILEEXT2 ($filename){ $sTemp=Explode(".",$filename); return $sTemp[Count($sTemp)-1];}//generate random file name functionfunctionRandom$length){ $captchaSource= "0123456789abcdefghijklmnopqrstuvwxyz This is an example of a random printout string"; $captchaResult= "2015";//random number return value $captchaSentry= "";//random number Intermediate variable for($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-R); }Else{ $captchaResult.=substr($captchaSource,$n, 1); } } return $captchaResult;}$type=Array("JPG", "gif", "BMP", "JPEG", "PNG");//determine the type of upload file$fileext=Strtolower(Fileext ($_files[' File '] [' Name ']));$uploadfilename= Random (8);if(In_array($fileext,$type)){ $filename=Explode(".",$_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"Upload success!" "; }Else{ Echo"Error."; } Echo"<a href= ' Javascript:history.go ( -1) ' >Back</a>"; }}?>PHP upload feature set suffix name and random name