How to use the php encapsulation class to upload images can be directly referenced _ PHP Tutorial

Source: Internet
Author: User
How can I use the php encapsulation class to enable direct reference for image uploads .? Phpclassimage {*** complete image Upload ** @ paramarray $ array of file information to be uploaded, used for the array of five elements * @ returnmixed if the execution is successful, the upload is returned
Class image {/*** complete image Upload ** @ param array $ array of file information to be uploaded, array used for five elements * @ return mixed if the execution is successful, the uploaded file name is returned; otherwise, false */public function upload ($ file) is returned) {if ($ file ['error'] = 0) {$ allow_types = array ('image/jpeg ', 'image/pjpeg', 'image/png ', 'image/GIF'); if (in_array ($ file ['type'], $ allow_types) {$ maxsize = 2000000; if ($ file ['size'] <= $ maxsize) {// Upload // you need to rename the file, 1 to prevent irregular characters from appearing in the file name, 2, avoid duplicate names // use timestamps and random numbers Format // how to obtain the suffix? Get the extension name in the original file name // The last point in the file name is intercepted to the end is the extension // strrchr (in which string query, query string); $ new_filename = time (). mt_rand (10000,999 99 ). strrchr ($ file ['name'], '. '); // move // This function returns whether the movement is successful or fails if (move_uploaded_file ($ file ['tmp _ name'], 'Images /'. $ new_filename) {return $ new_filename; }}}// only one type of file name is returned, and all others return false; }}?> // Configure //-------------------------------------------------------------------------------------
 Upload ($ img); mysql_connect ('localhost', 'root', '000000'); mysql_select_db ('lyb'); mysql_query ('set names utf8 '); $ q = "insert test_image (name, url) values ('$ user',' $ img ')"; // var_dump ($ q ); $ result = mysql_query ($ q); if ($ result) {echo "added successfully .....

";} Failed to add else {echo... ";}?> // Configure //-------------------------------------------------------------------------------------- Image Upload class

Http://www.bkjia.com/PHPjc/371999.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/371999.htmlTechArticle? Php class image {/*** complete image Upload ** @ param array $ array of file information to be uploaded, the array used for the five elements * @ return mixed. if the execution is successful, the system returns the upload...

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.