-1

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?

Community
  • 1
  • 1
  • 1
    What have you tried so far?! Do you have any own ideas how this could be solved? – Neysor Mar 11 '12 at 11:03
  • Why do u want it to be deleted? So that just one user can download it or some other reason? Your question might be closed if u don't be more specific – rfcdejong Mar 11 '12 at 11:07
  • Check the PHP manual for unlink(): http://il.php.net/manual/en/function.unlink.php – Ynhockey Mar 11 '12 at 11:11

2 Answers2

0

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.

botzko
  • 630
  • 3
  • 8
-1

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.

DanRedux
  • 9,119
  • 6
  • 23
  • 41