PHP Partial---Single-File Upload package class

Source: Internet
Author: User
Tags http post md5 encryption

<?PHP$fileinfo=$_files["MyFile"];functionUploadFile ($fileinfo,$allowext=Array(' jpeg ', ' jpg ', ' PND ', ' gif ', ' wbmp '),$flag=true,$maxsize=2097152){//Judging error Messagesif($fileinfo[' Error ']>0){    Switch($fileinfo[' Error '])        {             Case1:$mes= "The upload file exceeds the value of the upload_max_filesize option in the PHP configuration file";  Break;  Case2:$mes= "exceeds the limit size of form max_file_size";  Break;  Case3:$mes= "File part is uploaded";  Break;  Case4:$mes= "No Upload file selected";  Break;  Case6:$mes= "No temp directory Found";  Break;  Case7: Case8:$mes= "System Error";  Break; }        Exit($mes); }//determine if the upload file type is in the specified type    $allowext=Array(' jpeg ', ' jpg ', ' PND ', ' gif ', ' wbmp ');//define the allowed upload file types    $ext=Strtolower(End(Explode(‘,‘,$fileinfo[' name ']));//intercept upload file extension    if(!In_array($ext,$allowext))//determine if the extension of the uploaded file is in a defined type    {         Exit(' Illegal file type '); }//determine the upload file size    $maxsize= 2097152;//write the maximum number of bytes, you count    if($fileinfo[' Size ']>$maxsize)    {        Exit(' Upload file too large '); }        //determine if the file was uploaded via HTTP post    if(!Is_uploaded_file($fileinfo[' Tmp_name ']))    {        Exit(' File not uploaded by HTTP post ')); }        //detects if a real picture type is true, but not what is considered a change    $flag=true; if($flag)    {        if(!getimagesize($fileinfo[' Tmp_name ']))        {            Echo"Not a real picture type"; }        }        //determine if the folders stored on the server are not$path= ' uploads ';//file name stored on the server    if(!file_exists($path))    {        mkdir($path, 0777,true);//Create a directory if it does not exist        chmod($path, 0777);//Add a permission                }$uniname=MD5(uniqid(Microtime(true),true)).‘.‘.$ext;//by MD5 Encryption and other measures to name the filename, resulting in a unique file name        $destination=$path.‘ /‘.$uniname; if(!Move_uploaded_file($fileinfo[' Tmp_name '],$destination))//Uploading Files    {        Echo"File upload Failed"; }        return Array(        ' NewName ' =$destination, ' size ' =$fileinfo[' Size '], ' type ' = =$fileinfo[' Type ']            ); }

PHP Partial---Single-File Upload package class

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.