簡體   English   中英

unlink()無法正常工作

[英]unlink() is not working

  for($i=0; $i<count($_POST['list']); $i++) { 
            echo $_POST['list'][$i]; 
            if(is_file($_POST['list'][$i])) echo "ok"; else echo "false";
            unlink($_POST['list'][$i]);
       }

我正在嘗試刪除服務器中的圖像文件。

echo $_POST['list'][$i]輸出../Profile/JPN012/test2.JPG (圖像路徑)。

但是is_file()unlink()無法正常工作。 盡管我更改了所有目錄和圖像file(0777)權限file(0777) ,但它不起作用。

(Linux OS環境)

有什么問題??

我認為問題在於您在is_file中的文件路徑參數並取消鏈接。 如果您可以在調用is_file或取消鏈接之前將目錄更改為文件所在的位置,則將更加容易。 之后,您只能使用is_file('test2.png')之類的文件名。

   <?php
    $old = getcwd(); // Save the current directory
    chdir($path_to_file);
    unlink($filename);
    chdir($old); // Restore the old working directory    
   ?>

(來源: http : //au1.php.net/chdir

檢查服務器中的路徑,最有可能是

$compositefilename = PATH_TO_YOUR_WEB_ROOT . "/composite/" . $compositeresult;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM