我最初通過mysql顯示圖像。現在我想通過上傳的圖像替換最初的圖像。我可以這樣做嗎?我使用此代碼在網頁上上傳圖像PHP:通過上傳的圖像替換mysql中存儲的圖像
$UPLOADDIR = "upload/";
// if the form has been submitted then save and display the image(s)
if(isset($_POST['Submit']))
{
// loop through the uploaded files
foreach ($_FILES as $key => $value)
{
$image_tmp = $value['tmp_name'];
$image = $value['name'];
$image_file = "{$UPLOADDIR}{$image}";
// move the file to the permanent location
if(move_uploaded_file($image_tmp,$image_file))
{
echo <<<HEREDOC
<div style="float:left;margin-right:10px">
<img src="{$image_file}" alt="file not found" /></br>
</div>
HEREDOC;
}
else
{
echo "<h1>image file upload failed, image too big after compression</h1>";
}
}
}
else
{
?>
<form name='newad' method='post' enctype='multipart/form-data' action=''>
<table>
<tr>
<td><input type='file' name='image'></td>
</tr>
<tr>
<td><input name='Submit' type='submit' value='Upload image'></td>
</tr>
</table>
</form>
<?php
}
?>
你的意思是說,你想更新現有的圖像?請更清楚! –
@ CodingAnt-是的,我想這樣做。 –
在db中更新圖像信息並刪除/替換舊圖像 –