我正在嘗試將圖像上傳到文件夾(圖像)並將文件路徑顯示到表列以引用上傳的圖像。 (示例)上傳的圖片:(report.jpg)將圖片存儲到文件夾中(圖片)現在創建網址到圖片< img src =「https://www.****.com/images/report.jpg」alt =「」 /> unfortunatley我已經想出了其中只存儲文件名在該表(report.jpg)將src img添加到mysql表中
<?php
if ($_POST["action"] == "Load") {
$folder = "images/";
move_uploaded_file($_FILES["filep"]["tmp_name"], "$folder".$_FILES["filep"]["name"]);
echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";
$result = mysql_connect("**", "**", "**") or die ("Could not save image name Error: " . mysql_error());
mysql_select_db("testing") or die("Could not select database");
mysql_query("INSERT into links (hyper_links) VALUES('".$_FILES['filep']['name']."')");
if ($result) {
echo "Image name saved into database";
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}
?>
<form action=sample.php method=post enctype="multipart/form-data">
<table border="0" cellspacing="0" align=center cellpadding="3" bordercolor="#cccccc">
<tr>
<td>File:</td>
<td><input type="file" name="filep" size=45/></td>
</tr>
<tr>
<td colspan=2>
<p align=center>
<input type=submit name=action value="Load"/>
</p>
</td>
</tr>
</table>
</form>
有一個看看我這個問題的答案:[全安全圖片上傳腳本](http://stackoverflow.com/questions/38509334/全安全圖像上傳腳本/ 38712921#38712921)只要按照它通過。您將學習到關於安全性和圖像上傳腳本的相當多的內容,並且最終您將擁有一個功能完整的腳本。 – icecub
感謝您的幫助,我上面編輯了我的問題,告訴你我想輸出到列(超鏈接),原因是我使用Navicat加載數據庫並顯示鏈接,以便我可以從Navicat內部查看。 (加載圖像到數據庫只是佔用了太多的時間和大小,所以我決定嘗試加載網址 – INOH
如果圖像的路徑永遠不會改變,那麼你需要在數據庫中記錄的所有內容都是文件名而不是完整的url,因爲你可以在運行時生成路徑 – RamRaider