Php simple file Image Upload class

Source: Internet
Author: User

Php simple file Image Upload class

This file upload class can upload gif ",". jpg ",". jar ",". jad ",". mid ",". mp3 ",". mid ",". bmp ",". wav ",". rm ",". wmv file format. If you want to support other formats, you can design $ this-> file_type ,.

<? Php
Class upload {

Var $ file_type;
Var $ file_size;
Var $ file_name;
Var $ exname;
Var $ datetime;


Function up ($ post_name, $ path ){
$ This-> file_name = $ _ FILES [$ post_name] ["name"];
$ This-> exname = strtolower (substr ($ this-> file_name, strrpos ($ this-> file_name ,".")));
$ This-> file_size = $ _ FILES [$ post_name] ["size"];
$ This-> file_type = array (". gif ",". jpg ",". jar ",". jad ",". mid ",". mp3 ",". mid ",". bmp ",". wav ",". rm ",". wmv ");
$ This-> datetime = date ("YmdHis ");
If (! In_array ($ this-> exname, $ this-> file_type )){
Print ("<script language = 'javascript '> ");
Print ("alert ('format not supported! ');");
Print ("history. back ();");
Print ("</script> ");
Break;
} Else'if ($ this-> file_size> "50000 "){
Print ("<script language = 'javascript '> ");
Print ("alert ('the image size cannot exceed 50KB! ');");
Print ("history. back ();");
Print ("</script> ");
Break;
} Else {
Move_uploaded_file ($ _ FILES [$ post_name] ["tmp_name"], $ path. $ this-> datetime. $ this-> exname );
}
}

Function fileName (){
$ Pic = $ this-> datetime. $ this-> exname;
Return $ pic;
}

}
?>
 


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.