Possible Duplicate:
deleting a file after user download it
I'm doing my a mini project in college written in PHP. I want to delete a csv file after a user has downloaded it. How can i get this done?
Possible Duplicate:
deleting a file after user download it
I'm doing my a mini project in college written in PHP. I want to delete a csv file after a user has downloaded it. How can i get this done?
You must create php script that will be used to download the file. In this script you will send the headers and then read end print the file content. After this you can deleate it in the script
<?php
//1. set headers
header('Content-type: text/csv');
header('Content-disposition: attachment;filename=MyVerySpecial.csv');
//2. get and send file content - you must secure the path (remove all ../ ./ and other possible)
echo file_get_contents('./' . $_GET['file_name']);
//3. delete the file
unlink('./' . $_GET['file_name']);
That's all.
Either create a page that will echo out the same headers and content as the file, and then delete the file, possible using $_GET['filename'] to output the correct file, and unlink to delete it.