2015-06-02 194 views
0

我想刪除特定文件名到一個文件夾取決於用戶的動作,我收到這樣的警告:PHP刪除文件到文件夾中

警告:取消鏈接():HTTP不允許取消鏈接在

這是具有提供導航到deleteRecord.php按鈕的代碼

> <script>             //btn delete 
>   $(".btn_delete").click(function(){ 
>   var id = $(this).closest('tr').children('td:first').text(); 
>    //alert(id);           
>    var x; 
       if (confirm("Are you sure you want delete this record?") == true) { 
>    //alert ("You pressed OK!");              
>    
>    location.href='deleteRecord.php?filename='+filename; 
>     } else { 
>      //alert ("You pressed Cancel!"); 
>      return false;   } 
>   }); 
>  </script> 

這工作,我把它很好地展現給從哪裏來變量ID

現在這個是PHP頁面返回的警告:

$filename = $_GET['filename']; //get the filename like "yo.jpg" 

$path = "http://www.here I have the exact address to the folder/"; 

unlink($path . '/' . $filename); 

,這是結果,我會再次把它!

******警告:取消鏈接():HTTP不允許斷開鏈接在******

有什麼建議?有什麼建議?請抱歉我的英語,我正在學習!

+2

您無法取消的URL。您取消鏈接文件系統上的文件。 – Devon

+0

'http://yoursite.com/delete.php?file =/etc/passwd'消毒並驗證您的輸入。 – Sammitch

回答

3

您需要將服務器路徑傳遞給文件作爲參數傳遞給unlink()而不是URL,例如:

unlink('/var/www/mywebsite.com/images/myimage.jpg')