Php file upload (powerful File Image Upload class ). Php file upload (powerful File Image Upload class) This file Upload utility code allows you to easily upload your specified file or image, at the same time, you can quickly restrict the upload of image files. php files (powerful File Image Upload class) This file Upload utility code can be easily uploaded to your specified file or image, you can also quickly restrict the class or size of uploaded image files.
Php Tutorial file upload (powerful File Image Upload class)
This file Upload utility code allows you to easily upload a specified file or image, and quickly restrict the class or size of uploaded image files.
/*
* 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 ('image 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 ('the image size exceeds the maximum size allowed by the system! ');
Exit;
}
// Check the iamge's type
If (! In_array ($ file ["type"], $ this-> up_img_types ))
{
Return $ img_type = fn_function: alert_msg ('image 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 ('the image resolution exceeds the maximum value allowed by 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 ('file moving 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
}
}
Upload (powerful File Image Upload class) This file Upload utility code allows you to easily upload your specified file or image, while also allowing you to quickly restrict the upload of image files...