I'm trying to create a secure document retrieval system for logged in users.
First I check if the user is logged in. If they are I progress to copy the file from the protected directory on the server to the web accessible space within the users current directory.
I then redirect them to the URL the file is now within. Tell the code to sleep for 10 seconds to allow slow connections time to download the file and then to delete it so the link is no longer usable by others.
My problem is that after the header the sleep function is not working. I tried removing the if statement and this made the script sleep for 10 seconds and then unlink the file before redirecting the user so the link as already broken.
I'm struggling to find a way to make the script sleep for 10 seconds and still execute the code AFTER the redirect has happened.
<?php
if(!isset($_SESSION['id'])){
header("location:../../../");
}
else {
echo copy('C:\directorypath\test.xls','test.xls');
if(header("location:../docs/test.xls")){
sleep("10");
unlink("test.xls");
}
}
?>