Php Plugin-file upload code-PHP source code

Source: Internet
Author: User
Ec (2); php connector-file upload code & lt ;? Php & nbsp; if (! Empty ($ _ FILES [& quot; uploadImage & quot;]) {& nbsp; getfilename & nbsp; $ filenamebasename ($ _ FILES [uploadImage] [name]); & nb script ec (2); script

Php Plugin-file upload code

If (! Empty ($ _ FILES ["uploadImage"]) {
// Get file name
$ Filename = basename ($ _ FILES ['uploadimag'] ['name']);

// Get extension
$ Ext = substr ($ filename, strrpos ($ filename, '.') + 1 );

// Check for jpg only
If ($ ext = "jpg "){
// Generate unique file name
$ NewName = 'images/'. time ().'. '. $ ext;

// Upload files
If (move_uploaded_file ($ _ FILES ['uploadimag'] ['tmp _ name'], $ newName ))){

// Get height and width for image uploaded
List ($ width, $ height) = getimagesize ($ newName );

// Return json data
Echo '{"image ":"'. $ newName. '"," height ":"'. $ height. '"," width ":"'. $ width. '"}';
}
Else {
Echo '{"error": "An error occurred while moving the files "}';
}
}
Else {
Echo '{"error": "Invalid image format "}';
}
}
?>

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.