Greetings,
Currently, I have a page that once a user selects a file they want to download, it moves and renames the file from another folder to the download folder, then executes the file download.
What I want to accomplish is to delete the file after the download of it has completed. I tried to execute a simple sleep command within the page, but seems to execute the sleep command prior to the header command to download the page:
Any ideas on how I can accomplish this? Will putting the sleep and unlink cmds in another file alleviate the problem possibly?
Thank you for your time.
- Dan
Currently, I have a page that once a user selects a file they want to download, it moves and renames the file from another folder to the download folder, then executes the file download.
What I want to accomplish is to delete the file after the download of it has completed. I tried to execute a simple sleep command within the page, but seems to execute the sleep command prior to the header command to download the page:
Code:
<?php
$rdmint=rand(10000, 99999);
$hiddenpath='/hiddenpath/';
$downloadpath='/download/';
$filename='bigfile';
$destnewfile="$filename$rdmint.zip";
$file="$hiddenpath$filename.zip";
$newfile="$downloadpath$destnewfile";
if(copy($file, $newfile))
{
echo "File copied successfully.";
}
else
{
echo "Failed to copy $file, please contact the Helpdesk.";
}
header("Location: [URL unfurl="true"]https://download/$destnewfile");[/URL]
sleep(60);
if (unlink($newfile))
{
echo "File moved from server successfully.";
}
?>
Any ideas on how I can accomplish this? Will putting the sleep and unlink cmds in another file alleviate the problem possibly?
Thank you for your time.
- Dan