簡體   English   中英

取消鏈接不適用於我使用guzzle下載的壓縮文件

[英]Unlink doesn't work for gzipped files that I downloaded using guzzle

我使用foreach循環下載了許多壓縮文件,在每個循環中都將文件解壓縮。 到目前為止,一切都還好,但是循環結束時我想取消鏈接壓縮文件。 代碼如下。

...
... // Previous processes
...

$destinationPath = './files/lld/' . $data['hour'] . '.gz';
fopen($destinationPath, 'w+');

...
... // Download processes
...

// Unzip
$gzfile = gzopen($destinationPath, "rb");
$tsvFile = fopen($destinationTsvPath, "w");

while ( ! gzeof($gzfile)) 
{
    $string = gzread($gzfile, 4096);
    fwrite($tsvFile, $string, strlen($string));
}

gzclose($gzfile);
fclose($tsvFile);

// Delete
unlink($destinationPath);

除取消鏈接過程外,其他所有東西都在工作,並且沒有任何錯誤日志。 我在這個網站上讀過類似的問題,答案之一是在gzlose()函數之后使用unlink()。 我已經嘗試過,但是沒有結果。

似乎您沒有足夠的權限刪除該文件。 我建議您像這樣在unlink()之前執行chmod(這將嘗試更改權限):

fclose($destinationPath);
chmod($destinationPath, 777);
unlink($destinationPath);

如果這不起作用,則將目錄(用於存儲這些文件的目錄)的權限設置為775 您可以通過SSH或FTP執行此操作。

暫無
暫無

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

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