Gets the upload temporary file path $uploadedfile = $_files[' UploadFile ' [' Tmp_name '];//gets the source file resource handle. The receive parameter is the picture path, the return handle $source = Imagecreatefromjpeg ($uploadedfile);//Gets the file's long width list ($width, $height) = getimagesize ($ UploadedFile), if ($width > $height) {$xoord = Ceil (($width-$height)/2); $width = $height;} else {$yoord = Ceil (($height- $width)/2); $height = $width;} Create a picture. The receive parameters are wide-height, which returns the generated resource handle $thumb = Imagecreatetruecolor (100,100);//Large map//The source file is cut all fields and scaled down to the target picture. The first two are resource handles imagecopyresampled ($thumb, $source, 0,0, $xoord, $yoord, 100,100, $width, $height);//Picture shows imagejpeg ($thumb, ", 100);
The above is the picture cutting process, assuming I can directly through the $db->select|update|insert to operate the database, how do I want to improve the above code, to upload the image after the cut into 2 into the MySQL database?
Reply content:
Gets the upload temporary file path $uploadedfile = $_files[' UploadFile ' [' Tmp_name '];//gets the source file resource handle. The receive parameter is the picture path, the return handle $source = Imagecreatefromjpeg ($uploadedfile);//Gets the file's long width list ($width, $height) = getimagesize ($ UploadedFile), if ($width > $height) {$xoord = Ceil (($width-$height)/2); $width = $height;} else {$yoord = Ceil (($height- $width)/2); $height = $width;} Create a picture. The receive parameters are wide-height, which returns the generated resource handle $thumb = Imagecreatetruecolor (100,100);//Large map//The source file is cut all fields and scaled down to the target picture. The first two are resource handles imagecopyresampled ($thumb, $source, 0,0, $xoord, $yoord, 100,100, $width, $height);//Picture shows imagejpeg ($thumb, ", 100);
The above is the picture cutting process, assuming I can directly through the $db->select|update|insert to operate the database, how do I want to improve the above code, to upload the image after the cut into 2 into the MySQL database?
Although it has been suggested that you do not exist in the database, but if you insist, I still tell you the way to do it, first you want to save the image of the field must be a blob
format, assuming you are ready for the database, in the code you need to make the following changes
Starting with the last line, use a temporary file to do the relay $tmp = '/tmp/'. MD5 (UNIQID ()); Imagejpeg ($thumb, $tmp, 100);//Convert data to a string $str = Mysql_real_escape_string (file_get_contents ($tmp)); /This is just a test of SQL, you can modify $sql = sprintf ("INSERT into Test (' Blob_column ') VALUES ('%s ')", $str); mysql_query ($sql);// Don't forget to delete the temporary document unlink ($TMP);