PHP upload feature set suffix name judgment and random name, php upload suffix named _php tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    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.