nadeemshafi9 Posted February 10, 2009 Share Posted February 10, 2009 i would like to delete or set permissions on a file immediately after download, i am creating a file and will allow the user to download it but it need to be deleted as soon as its downloaded, is there a way of doing this. I was also wondering can you you create a file but not keep it on your server but just let the user download it. i know JavaScript is involved. can someone give me some plain English ideas. I basically want to stop people from manually downloading confidential data files yet allow the user to create dumps etc and download them. thanks Quote Link to comment Share on other sites More sharing options...
waynewex Posted February 10, 2009 Share Posted February 10, 2009 if(is_file($directory_of_file)){ unlink($directory_of_file); } Quote Link to comment Share on other sites More sharing options...
printf Posted February 10, 2009 Share Posted February 10, 2009 You really cannot be sure if the download is complete, but you can dump the file to browser and then delete it after you dump it. Something like... <?php ignore_user_abort (); set_time_limit ( 0 ); $file_path = './path/to/file.pdf'; $file_type = 'application/pdf'; $file_name = 'document.pdf'; header ( 'Cache-Control: max-age=31536000' ); header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header ( 'Content-Length: ' . filesize ( $file_path ) ); header ( 'Content-Disposition: filename="' . $file_name . '"' ); header ( 'Content-Type: ' . $file_type . '; name="' . $file_name . '"' ); readfile ( $file_path ); unlink ( $file_path ); exit (); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.