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  } ?> <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->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;   //termination function function F_over ($n) { echo $n Exi T ();   //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;   //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 } ?>