I download lots of gzipped files with foreach loop, in every loop unzip the file. Up to this point everything is okay, but end of the loop I want to unlink the gzipped file. Codes are below.
...
... // 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);
Except the unlink process everything is working, and there is no any error log. I have read similar questions in this site, one of the answers is to use unlink() after gzlose() function. I have tried but there is no result.
It seems you do not have enough permissions to remove the file. I suggest you perform a chmod before unlink()
like this (this will try to change permission):
fclose($destinationPath);
chmod($destinationPath, 777);
unlink($destinationPath);
If this does not work, then set directory, where you are storing those files, permission to 775
. You can do this via SSH or FTP.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.