PHP upload feature set suffix name and random name, php upload suffix name
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"Back"; }}
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, 3); }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, 3); }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"Back"; }}?>
<title>Upload Image</title>
http://www.bkjia.com/PHPjc/1053808.html www.bkjia.com true http://www.bkjia.com/PHPjc/1053808.html techarticle php upload feature set suffix name and random name, php upload suffix named form.php html head meta HTTP-EQUIV = "content-type" content = "text/html" charset = " Utf-8 "title Upload Image ...