PHP File Upload class complete example _php tips

Source: Internet
Author: User
Tags php class php file upload

This example describes the php file upload class. Share to everyone for your reference, specific as follows:

/** $file =new class_file ($file _array, "flash/");
 $file->set_allow_type (Array ("JPG", "JPEG", "gif");
 $file->is_limit_size ();
   if (! $file->allow_file_size ()) {echo $file->error;
 Exit
    } if (! $file->allow_file_type ()) {echo $file->error;
  Exit ();
  }else if (! $file->uploadfile ()) {echo $file->error;
 Exit
   **/<?php class class_file{private $file _type;
   Private $file _size;
   Private $save _path;
   Private $file _path;
   Private $allow _type=array ();
   Private $allow _size;
   Private $file _name;
   Private $flag =false;
   Private $mime _type;
   Private $is _limit_size=false;
   Public $error;
       constructor function Class_file ($file _array, $save _path) {$this->file_path= $file _array[' tmp_name '];
       $this->file_size= $file _array[' size '];
       $this->file_type= $file _array[' type '];
    $this->save_path= $save _path;
    //Set allowed file type function Set_allow_type ($allow _type) {$this->allow_type= $allow _type;//Set allowed file size function set_allow_size ($allow _size) {$this->allow_size= $allow _size;
     //File Upload public Function UploadFile () {if (! $this->allow_file_type ()) {$this->file_name ();
     } if (Move_uploaded_file ($this->file_path, $this->save_path. $this->file_name)) {return true;
       }else{$this->error= "file upload failed";
     Return
     }//Judge file Upload type function Allow_file_type () {$this->file_name ();
       if (In_array ($this->mime_type, $this->allow_type)) {return true;
         }else{$this->error= "not allowed to upload type";
       Exit (); }//Determine file Upload size function allow_file_size ($size =100) {if ($this->is_limit_size) {$this->set_allow_siz
     E ($size);
     if ($this->allow_size>= $this->file_size) {return true;
     }else{$this->error= "exceeding file upload size limit";
   Restrict File size function is_limit_size () {$this->is_limit_size=true; }//file type and file namecalled function file_name () {$this->mime_type=substr ($this->file_type,strpos ($this->file_type, "/") +1);
    if ($this->mime_type== "Pjpeg") {$this->mime_type= "JPG";
    } if ($this->mime_type== "x-ms-wma") {$this->mime_type= "WMA";
    } if ($this->mime_type== "x-ms-wmv") {$this->mime_type= "WMV"; } $this->file_name=date ("Ymdhis"). ".
   $this->mime_type ";
   function _get_file_name () {return $this->file_name;

 }}?>

More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.