[英]how to protect deleting files from other folder
我為幾個用戶創建了一個簡單的文件管理。 結構:每個用戶在目錄uploads
都有一張地圖,如下所示:
uploads/john/-->files inside
uploads/bill/-->files inside
對於刪除文件,我使用此表格”
<form class="sfmform" method="post" action="">
<input type="hidden" name="deletefile" value="<?php echo $dir.'/'.$file">
<input type="submit" class="sfmdelete" name="delete" value="Delete">
</form>
var $dir.'/'.$file
顯示$dir.'/'.$file
的確切位置,例如: uploads/john/cat.jpg
讓我們假設:我是約翰 ,我知道另一個人的名字是比爾 。 而且我猜比爾在他的箔dog.jpg
還有一個名為dog.jpg
的文件
我打開瀏覽器檢查器以刪除自己文件夾中的文件,然后將隱藏的輸入表單uploads/john/cat.jpg
的值更改為uploads/bill/dog.jpg
,然后單擊刪除,我確實刪除了狗圖像沒帳單他的文件夾。
如何通過瀏覽器檢查器保護這種操作?
這是我通過瀏覽器檢查器來保護操作的操作: john
和bill
之類的文件夾的名稱由此變量生成: UserID
所有文件夾都位於uploads
目錄中。 所以看起來像: uploads/john/...
和uploads/bill/...
隱藏文本字段的值是使用$dir.'/'.$file
,始終看起來像uploads/john/file.jpg
現在,我將$UserID
與第一個/
之后的隱藏文件的值ot進行比較,如下所示:
$pieces = explode("/", $_POST['deletefile']);
$hiddenvalue = $pieces[1];
if( $UserID != $hiddenvalue ) { // if these values not the same
echo "Forbidden!";
exit;
}
我測試了它,似乎工作正常...
好! 它不是最專業的解決方案,但我想在沒有數據庫的情況下制作此腳本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.