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...