PHP Upload method (class) _ PHP Tutorial

Source: Internet
Author: User
PHP Upload method (class ). It is very simple. I often used the PHP method last time. I took it out from the class and it can be used directly or further improved, in the PHP100 video tutorial, I also explained in detail a very simple PHP Upload method, which is commonly used in the last PHP method. I used it for you from the class. it can be used directly, or you can continue to improve it, the bkJia video tutorial also details the PHP Upload method. For more information, see

/**
* Image Upload method-source and bkJia
* $ Maxsize = 500000 = 500 k;
* $ Updir = "up /";
* $ Upfile = $ _ FILES ["file_img"];
*/
Public function Get_file_upload ($ upfile, $ maxsize, $ updir, $ newname = date ){

If ($ newname = date)
$ Newname = date ("Ymdhs"); // use date as the file name
$ Name = $ upfile ["name"];
$ Type = $ upfile ["type"];
$ Size = $ upfile ["size"];
$ Tmp_name = $ upfile ["tmp_name"];

Switch ($ type ){
Case image/pjpeg:
Case image/jpeg:
$ Extend = ". jpg ";
Break;
Case image/gif:
$ Extend = ". gif ";
Break;
Case image/png:
$ Extend = ". png ";
Break;
}
If (empty ($ extend )){
The echo file type is incorrect. only jpg gif png format can be used;
}
If ($ size> $ maxsize ){
$ Maxpr = $ maxsize/1000;
Echo "Warning! The size of the uploaded image cannot exceed ";
}
If (move_uploaded_file ($ tmp_name, $ updir. $ newname. $ extend )){
Return $ newname. $ extend;
}
}

...

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.