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

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.