基本上我必須做的是將圖像寫入數據庫。使用imagejpeg將圖像重新映射到數據庫
據我瞭解imagejpeg函數 - 輸出應該是普通圖像數據,如果「字符串$文件名」沒有設置或NULL。 但它沒有,唯一的輸出是「1」(true)...
如何在不首先將圖像存儲在文件系統中並重新加載的情況下獲取圖像數據?
這是我的代碼示例:
// If it is the right filetype.
if ($_FILES[$dom_element]['type'] == 'image/jpeg' || $_FILES[$dom_element]['type'] == 'image/pjpeg') {
// Create the image recource.
$image_image = imagecreatefromjpeg($_FILES[$dom_element]['tmp_name']);
}
// Resize the image.
imagecopyresampled($image_image_p, $image_image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_width, $image_height);
// Write the image in the database (does not work this way -> output = "1")
mysql_select_db("$db_announcement");
$sql = "UPDATE announcement
SET announcement_guest_image_data = '" . addslashes(imagejpeg($image_image_p, NULL, $settings_image_quality)) . "',
announcement_guest_image_exists = 'yes'
WHERE announcement_timestamp = '$timestamp' AND announcement_guest_mail = '$global_mail'";
$sql = mysql_query($sql);
// Delete the image recources.
imagedestroy($image_image);
imagedestroy($image_image_p);
他需要使列類型成爲BLOB。 – wesside
是的,如果它還沒有的話。我質疑將數據存儲在數據庫中有多聰明,但這不是這個問題的關鍵...... – deceze
那就是它,完美的作品:-) – Andreas