PHP file upload code-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Phpif ($ _ FILES [file] [error] & nbsp; & gt; & nbsp; 0) {& nbsp; echo & nbsp ;! Problem:; & nbsp; switch ($ _ FILES [file] [error]) & nbsp; & nbsp ;{& nbsp; & nbsp; & nbsp; & script ec (2); script


If ($ _ FILES ['file'] ['error']> 0 ){
Echo '! Problem :';
Switch ($ _ FILES ['file'] ['error'])
{
Case 1: echo 'file size exceeds server limited ';
Break;
Case 2: echo 'the file is too large! ';
Break;
Case 3: echo: only part of the file is loaded! ';
Break;
Case 4: echo 'file loading failed! ';
Break;
}

Exit;
}
If ($ _ FILES ['file'] ['SIZE']> 1000000 ){
Echo 'The file is too large! ';
Exit;
}
If ($ _ FILES ['file'] ['type']! = 'Image/jpeg '& $ _ FILES ['file'] ['type']! = 'Image/gif '){
Echo: The file is not JPG or GIF! ';
Exit;
}
$ Today = date ("YmdHis ");
$ Filetype = $ _ FILES ['file'] ['type'];
If ($ filetype = 'image/jpeg '){
$ Type = '.jpg ';
}
If ($ filetype = 'image/gif '){
$ Type = '.gif ';
}
$ Upfile = 'upfile/'. $ today. $ type;
If (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name'])
{
If (! Move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], $ upfile ))
{
Echo 'failed to move the file! ';
Exit;
}
}
Else
{
Echo 'problem! ';
Exit;
}
Echo 'success!
';
Echo 'file size: '. $ _ FILES ['file'] ['SIZE']. 'byte '.'
';
Echo 'file path: '. $ upfile;
Echo'

'.'

';
$ Dirr = 'upfile /';
$ Dir = opendir ($ dirr );
Echo $ dirr. '-- Listing:

    ';
    While ($ file = readdir ($ dir )){
    Echo"
  • $ File
  • ";
    }
    Echo'
';
Closedir ($ dir );
?>

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.