user3098202
user3098202

Reputation: 99

How to unlink the temporary files from /tmp folder in linux using php code

foreach (new DirectoryIterator($tempFilesPath) as $fileData)
{
    $fileName           = $fileData->getFileName();
    $fullFilePath       = $tempFilesPath.$fileName;
    @chmod( $fullFilePath,777);
    if (stristr($fileName, ".csv") !== false )
    {
        unlink($fullFilePath);
    }
}

Permission denied error when try to unlink the file from /tmp folder

Upvotes: 1

Views: 2708

Answers (1)

suspectus
suspectus

Reputation: 17258

The correct thing to do is not delete the files in /tmp. The system will clear files in /tmp by default every time the system is rebooted. This is the default but can be re-configured to delete more frequently. Or place the temporary files in a another directory.

Upvotes: 1

Related Questions