PHP File Upload (powerful file image upload Class) This file upload utility code, you can easily upload your designated files or pictures, but also can quickly limit the upload of pictures file class or size.
PHP Tutorial File Upload (powerful file image upload Class)
This file upload the utility code, you can easily upload your designated files or pictures, but also can quickly limit the upload of image file class or size.
/*
* Created on 2010-6-21
*
* The class for image to upload
*
* Made by S71ence
*
* @ $user _id
* @ $max _file_size
* @ $max _image_side
* @ $destination _folder
*
* Return:
* @$_cookie[' Img_path ']
* @ $img _unfind
* @ $img _type
* @ $mkdir _warry
* @ $img _side_too_big
* @ $img _exist
* @ $img _move
* @ $img _upload_sucess
*/
Header (' Content-type:text/html;charset=utf-8 ');
Class Image_upload extends Fn_function
{
Private $user _id;
Private $max _file_size; Allow the image ' s size
Private $max _image_side; Allow the image ' s side
Private $destination _folder; Image ' s storage path
Private $img _preview;
Private $img _preview_size;
Private $cookie _set; The cookie ' s name
function __construct ($user _id, $max _file_size, $max _image_side, $destination _folder, $img _preview, $img _preview_size , $cookie _set)
{
$this->user_id= $user _id;
$this->max_file_size= $max _file_size;
$this->max_image_side= $max _image_side;
$this->destination_folder= $destination _folder;
$this->img_preview= $img _preview;
$this->img_preview_size= $img _preview_size;
$this->cookie_set= $cookie _set;
$this->get_date ();
$this->get_image_type ();
}
Private Function Get_date ()
{
$this->date=fn_function::get_server_date ();
return $this->date;
}
function Get_image_type ()
{
$this->up_img_types=array (
' Image/jpg ',
' Image/jpeg ',
' Image/png ',
' Image/pjpeg ',
' Image/gif ',
' Image/bmp ',
' Image/x-png '
);
return $this->up_img_types;
}
function Upload_image ()
{
if ($_server[' request_method '] = = ' post ')
{
Check the IAMGE is exist
if (!is_uploaded_file ($_files["Upfile" ["Tmp_name"]))
{
return $img _unfind=fn_function::alert_msg (' picture does not exist! ');
Exit
}
$file = $_files["Upfile"];
Check the Iamge ' s size
if ($this->max_file_size < $file ["size"])
{
return $img _side_too_big=fn_function::alert_msg (' picture size exceeds the maximum system allowable value! ');
Exit
}
Check the Iamge ' s type
if (!in_array ($file ["type"], $this->up_img_types))
{
return $img _type=fn_function::alert_msg (' picture type does not match! ');
Exit
}
if (!file_exists ($this->destination_folder))
{
if (!fn_function::mkdirs ($this->destination_folder))
{
return $mkdir _warry=fn_function::alert_msg (' Directory creation failed! ');
Exit
}
}
$file _name= $file ["Tmp_name"];
$image _size = getimagesize ($file _name);
$pinfo =pathinfo ($file ["name"]);
$file _type= $pinfo [' extension '];
$destination = $this->destination_folder.time (). ".". $file _type;
Setcookie ($this->cookie_set, $destination);
if ($image _size[0]> $this->max_image_side | | $image _size[1]> $this->max_image_side)
{
return $img _side_too_big=fn_function::alert_msg (' Picture resolution exceeds the maximum allowable value of the system! ');
Exit
}
$overwrite = "";
if (file_exists ($destination) && $overwrite! = True)
{
return $img _exist=fn_function::alert_msg (' The file with the same name already exists! ');
Exit
}
if (!move_uploaded_file ($file _name, $destination))
{
return $img _move=fn_function::alert_msg (' Move file Error! ');
Exit
}
$img _upload_sucess= "Upload successful
";
if ($this->img_preview==1)
{
$img _src= "img_preview_size)." Height= ". ($image _size[1]* $this->img_preview_size);
$img _upload_sucess.= $img _src;
}
return $img _upload_sucess;
}
}
function __destruct ()
{
Clear
}
}
http://www.bkjia.com/PHPjc/444883.html www.bkjia.com true http://www.bkjia.com/PHPjc/444883.html techarticle php File Upload (powerful file image upload Class) This file upload utility code, you can easily upload your designated files or pictures, but also can quickly limit the upload of pictures file class ...