PHP image upload class with Image Display _ PHP Tutorial

Source: Internet
Author: User
PHP image upload class with image display. This is a PHP file Upload class with image display. In fact, it can be made into a function. but it is still a little fun to make it into a class .~~~~ JavaScript should have been used to verify the Upload file type. this is a PHP file Upload class with image display. actually, you can make it into a function. but it is a little fun to make it a class. ~~~~
I should have used JS to verify the Upload file type, but I am too lazy to do it.





Untitled Document





Class upload
{
Var $ upload_name;
Var $ upload_tmp_address;
Var $ upload_server_name;
Var $ upload_filetype;
Var $ file_type;
Var $ file_server_address;
Var $ image_w = 900; // The width of the image to be displayed
Var $ image_h = 350; // The height of the image to be displayed
Var $ upload_file_size;
Var $ upload_must_size = 50000; // specify the size of the file to be uploaded.
Function upload_file ()
{
$ This-> upload_name = $ _ FILES ["file"] ["name"]; // Get the Upload file name
$ This-> upload_filetype = $ _ FILES ["file"] ["type"];
$ This-> upload_server_name = date ("Y_m_dH_ I _s"). $ this-> upload_name;
$ This-> upload_tmp_address = $ _ FILES ["file"] ["tmp_name"]; // get a temporary address
$ This-> file_type = array ("image/gif", "image/pjpeg"); // type of the file that can be uploaded
$ This-> upload_file_size = $ _ FILES ["file"] ["size"]; // size of the uploaded file
If (in_array ($ this-> upload_filetype, $ this-> file_type ))
{If ($ this-> upload_file_size <$ this-> upload_must_size)
{
Echo ("Upload successful, thank you for your support ");
$ This-> file_server_address = "D: \ usr \ www \ html \ upload/". $ this-> upload_server_name;
Move_uploaded_file ($ this-> upload_tmp_address, $ this-> file_server_address); // remove from the TEMP directory
Echo ("file_server_address width = $ this-> image_w height = $ this-> image_h/>"); // display the image


}
Else
{
Echo ("The file capacity is too large ");
}
}
Else
{
Echo ("This file type is not supported. please select again ");
}

}

}
$ Dd = new upload;
$ Dd-> upload_file ();
?>

Bytes .~~~~ I should have used JS to verify the Upload file type, but I am too lazy to do it...

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.