因此,我創建了一個小型管理面板,php用于將文件上傳到將顯示在主頁上的目錄中?,F在的問題是,如何刪除文件?我已經看到人們正在使用Ajax并jQuery執行此操作,但我不明白如何使用按鈕執行此操作。這是我生成圖像和刪除按鈕的函數,但是當有人單擊按鈕時,它應該刪除關聯的圖像,我不知道如何傳遞圖像路徑或其他內容:$dirname = "img_show/";$images = glob($dirname."*.{jpg,gif,png}",GLOB_BRACE);foreach($images as $image) { echo '<img src="'.$image.'" width="25%" /><br/>'; echo '<form method="post"> <input type="submit" name="delete" value="Effacer" /> </form>'; }
1 回答

繁星淼淼
TA貢獻1775條經驗 獲得超11個贊
看起來您正在嘗試刪除從“img_show”目錄中檢索的文件,而不是將其存儲在數據庫中。
刪除所選文件的最簡單方法是使用以下內容更新您的代碼,
// Delete an image if the delete button was clicked
if(isset($_POST['delete']) && $_POST['delete'] == 'Effacer') {
unlink($_POST['file']);
}
// Print the available list of images in the directory
$dirname = "img_show/";
$images = glob($dirname."*.{jpg,gif,png}",GLOB_BRACE);
foreach($images as $image) {
echo '<img src="'.$image.'" width="25%" /><br/>';
echo '<form method="post">
<input type="hidden" name="file" value="'. $image .'" />
<input type="submit" name="delete" value="Effacer" />
</form>';
}
- 1 回答
- 0 關注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消