Object-Oriented---packaging file uploading ideas

Source: Internet
Author: User

<?PHPHeader("Content-type:text/html;charset=utf8");//Get data Information$data=$_files;//iterate through the way to a single arrayforeach($data  as $key=$val){    $arr=$val;}//determine if the file is validif(!Is_array($arr) ||Empty($arr)){    Echo"Invalid file"; die;}//get suffixif(!Empty($arr[' Name '])) {    $info=PathInfo($arr[' Name ']); $st=$info[' DirName ']; $ext=$info[' extension '];}//determine the type of errorSwitch($arr[' Error ']){     Case1:Echo"The uploaded file exceeded the value of the Upload_max_filesize option limit in php.ini. "; die; Break;  Case2:Echo"The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "; die; Break;  Case3:Echo"The file is only partially uploaded. "; die; Break;  Case4:Echo"No files were uploaded. "; die; Break;  Case6:Echo"Could not find the Temp folder. "; die; Break;  Case7:Echo"File write failed. "; die; Break;}//set the type of file upload allowed$types=Array(' Image/gif ', ' image/jpeg ', ' image/jpg ', ' image/pjpeg ', ' image/x-png ', ' image/png ');//set the size of allowed file uploads$sizes= 204800;//less than 200kbif(!In_array($arr[' type '],$types)){    Echo"File type is not allowed";}if($arr[' Size ']>$sizes){    Echo"The file is too big"; die;}//determine if the file directory is presentif(!Is_dir('./upload ')){    mkdir(' Upload ');}//determine if the upload directory in the current directory exists for the file//if there is no upload directory, you need to create it, upload directory permissions for 777if(file_exists("upload/".$arr["Name"])){    Echo $arr["Name"]. "The file already exists. "; die;}Else{    //If the file is not present in the upload directory, upload the file to the upload directory    $path= "upload/".$arr[' Name '].$st.$ext;//Path    Move_uploaded_file($arr["Tmp_name"],$path);}Echo $path;

Object-Oriented---packaging file uploading ideas

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.