$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$fileName_th = $_FILES['thumbnail']['name'];
$tmpName_th = $_FILES['thumbnail']['tmp_name'];
$fileSize_th = $_FILES['thumbnail']['size'];
$fileType_th = $_FILES['thumbnail']['type'];
$fp_th = fopen($tmpName_th, 'r');
$content_th = fread($fp_th, filesize($tmpName_th));
$content_th = addslashes($content_th);
fclose($fp_th);
if(!get_magic_quotes_gpc())
{
$fileName_th = addslashes($fileName_th);
}
$query = "INSERT INTO Images (profile_id, thumb, name, size, type, content) ".
"VALUES ('$profile_id', 0, '$fileName', '$fileSize', '$fileType', '$content'),('$profile_id', 1, '$fileName_th', '$fileSize_th', '$fileType_th', '$content_th') ";
$r = mysqli_query($dbc, $query);
echo "<br>$first_name uploaded successfully";
這是我用來上傳我的圖像到我的數據庫的方法。現在,我想要做的是有一個編輯頁面,它可以編輯我的表單元素(如文本),並對圖像進行更改。已將圖像上載到mysql數據庫,但是我可以檢索它以查看編輯頁面嗎?
我知道如何查詢文本元素並將它們放回到它們各自的輸入字段中,但是如何爲圖像等文件執行此操作?
問題:將文件「上傳」到數據庫的最佳方式是什麼?這是我的方式嗎?還是有一種方法只是將文件寫入目錄並將路徑保存在數據庫中?
很好的例子如何顯示內聯圖像是有http://www.greywyvern.com/code/php/binary2base64 – FDisk 2011-01-05 19:37:46
不知道這一點,謝謝。不確定我對此感覺如何;) – 2011-01-05 19:52:48