Jump to content

Delete file immidiatly after download


nadeemshafi9

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/144592-delete-file-immidiatly-after-download/
Share on other sites

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 ();

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.