PHP image upload class attached to call method,
This example for everyone to share the PHP image upload class, for your reference, the specific content as follows
Call Method:
<?phpheader ("content-type:text/html; Charset=utf-8 "); Class instantiation: Include ("uppoo.php");//The file name of the class is Upoop.php$up=newupphoto; $submit =$_post[' Submit '];if ($submit = = "Upload") {$up- >get_ph_tmpname ($_files[' photo ' [' tmp_name ']), $up->get_ph_type ($_files[' photo ' [' type ']); $up->get_ph_ Size ($_files[' photo ' [' size ']), $up->get_ph_name ($_files[' photo ' [' name ']); $up->save (); >//uploading images to HTML:
Photo Source:
Upload class, save file name is called uppoo.php:
<?phpclass upphoto{public $previewsize = 0.125; Preview Picture scale public $preview = 0; Whether to generate a preview, is 1, no 0 public $datetime; Random number public $ph _name; Upload picture file name public $ph _tmp_name; Picture temporary file name public $ph _path= "./userimg/"; Upload file storage path public $ph _type; Picture type public $ph _size; Picture size public $imgsize; Upload image size for judging the display scale public $al _ph_type=array (' image/jpg ', ' image/jpeg ', ' image/png ', ' image/pjpeg ', ' image/gif ', ' image /bmp ', ' image/x-png '); Allow uploading of picture types public $al _ph_size=1000000; Allow upload of file size function __construct () {$this->set_datatime ();} function Set_datatime () {$this->datetime=date (" Ymdhis "); }//Get file type function Get_ph_type ($phtype) {$this->ph_type= $phtype;}//Get file Size function get_ph_size ($phsize) {$this- >ph_size= $phsize. "
"; } Get upload Temporary file name function get_ph_tmpname ($tmp _name) {$this->ph_tmp_name= $tmp _name; $this->imgsize=getimagesize ($tmp _name); }//Get the original file name function Get_ph_name ($phname) {$this->ph_name= $this->ph_path. $this->datetime.strrchr ($phname, " ."); STRRCHR gets the location of the last occurrence of the point of the file//$this->ph_name= $this->datetime.strrchr ($phname, "."); STRRCHR gets the point where the file last occurred return $this->ph_name; }//determine the upload file storage directory function Check_path () {if (!file_exists ($this->ph_path)) {mkdir ($this->ph_path); }}//Determine if the upload file exceeds the allowable size function check_size () {if ($this->ph_size> $this->al_ph_size) {$this->showerror (" Upload images over 2000KB "); }}//Determine file type function Check_type () {if (!in_array ($this->ph_type, $this->al_ph_type)) {$this->showerror ("Upload picture Type error "); }}//Upload picture function Up_photo () {if (!move_uploaded_file ($this->ph_tmp_name, $this->ph_name)) {$this- ShowError ("Error uploading file"); }}//Picture preview function Showphoto () {if ($this->preview==1) {if ($this->imgsize[0]>2000) {$this->imgsize[0]= $this->imgsize[0]* $this->previewsize; $this->imgsize[1]= $this->imgsize[1]* $this->previewsize; } Echo ("Ph_name}\" width=\ "{$this->imgsize[' 0 ']}\" height=\ "{$this->imgsize[' 1 ']}\" > "); }}//Error function ShowError ($ERRORSTR) {echo ""; Exit (); } function Save () {$this->check_path (); $this->check_size (); $this->check_type (); $this->up_photo (); $this->showphoto (); }}?>
The above is the whole content of this article, I hope that you learn PHP programming help.
http://www.bkjia.com/PHPjc/1127894.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127894.html techarticle PHP Image upload class attached to call method, this example for everyone to share the PHP image upload class, for your reference, the specific content as follows call method: Phpheader ("content-type:text/html; Charse ...