Classic PHP File Upload class

Source: Internet
Author: User
Tags date file size file upload mkdir php file php file upload return

In the classroom to write a classic file upload class, flexibility can also, you can refer to the use of

Upload file:

<?php/** * author:PHP100.com * date:2012-9-15 Classic File Upload class   **/ if (!empty ($_post[' Sub ')) {  Include (" Up.class.php ");      $up = new Up ($_files[' up ']); parameters, file flow required, "Specify directory, specify size, specify filename" optional &nbsp}  ?>   <form action= "method=" post "enctype=" multipart/ Form-data "> <input type=" File "name=" Up "> <input type=" Submit "Name=" sub "value=" Upload "> </form>   Upload class:   <?php/** * author:PHP100.com * date:2012-9-15 Classic File Upload class   **/ class up {   & nbsp Public $f _size;//defined file size     Public $f _sys;//receive file properties public $f _name;//custom file name public $f _dir;//Custom upload directory  //Ginseng Number: File stream, directory, size, filename function __construct ($sys, $dir = "", $size = "1", $name = "") {  $this->f_size= $size *1000000;   $this->f_sys= $sys;   $this->f_name= $name;   $this->f_dir= $dir;   $this-&GT;F_MV ();  //Judging file size    function is_size () {      if ($this->f_sys[' size ']<= $this->f_size ){   return true;  }else{   return false;  }    }//end       &NBS p;//determines the file type, returns the extension    function is_type () {  switch ($this->f_sys[' type ')) {case "image/x-png": $ok = ". PNG "; Break Case "Image/png": $ok = ". png"; Break Case "Application/pdf": $ok = ". pdf"; Break Case "Image/pjpeg": $ok = ". jpg"; Break Case "Image/jpeg": $ok = ". jpg"; Break Case "Image/jpg": $ok = ". jpg"; Break Default: $ok =false; Break return $ok;     &nbsp        //termination function    function F_over ($n) {     echo $n Exi T ();   &nbsp        //determine if a folder exists and create    function Is_dirs () {    if ($this->f_d IR) {if (!is_dir ($this->f_dir)) {    mkdir ($this->f_dir);} return $this->f_dir;} else{if (!is_dir ("YMD")) {    mkdir (Date ("YMD"));} return Date ("YMD");}    }     &nbs P      //file name definition, not defined and use timestamp &nbsP  function Is_name () {      if ($this->f_name) {  $FN = $this->f_name. $this->is_type ();  }else{  $FN =time (). Rand (100,999). $this->is_type ();    return $this->is_dirs (). /". $fn;   &nbsp        //upload file    function f_mv () {  $this->is_size ()? null: $this- >f_over ("File exceeds size");   $this->is_type () null: $this->f_over ("Incorrect file type");; Move_uploaded_file ($this->f_sys[' tmp_name '), $this->is_name ());  //Please continue to refine, watermark, et cetera  }    ?>

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.