473,553 Members | 2,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP unable to unlink after readfile()

314 Contributor
On my site I have a file that I generate in /var/tmp so that the user can download it. The script is as follows:

Expand|Select|Wrap|Line Numbers
  1. $file_path = '/var/tmp/up2606.csv';
  3. header('Cache-Control: public, must-revalidate');
  4. header('Pragma: hack');
  5. header('Content-Type: application/vnd.ms-excel');
  6. header('Content-Length: '.(string)(filesize($file_path)));
  7. header('Content-Transfer-Encoding: binary\n');
  8. header('Content-Disposition: attachment; filename="recv_data.csv"');
  9. readfile($file_path);
  10. unlink($file_path);
  11. ?>
So basically what I want to do is delete the file as soon as the user downloads it. (Earlier in the script the file is generated specifically for the user's session).
The script completely ignores the unlink though, as my /var/tmp directory still has all the files that are generated... the funny thing is I'm not getting any errors, so I'm not quite sure how to go about solving this one?
Jan 10 '08 #1
3 4769
314 Contributor
The problem has to be the fact that the user is dl'ing the file. The script executes and probly gives a hidden permission denied error somewhere. I can delete other files using this script, just not the one that's being downloaded...

The script went like this:
Expand|Select|Wrap|Line Numbers
  1. //same download process as before...
  2. $fh = fopen('/var/tmp/foo.bar', 'a');
  3. fputs($fh, 'test');
  4. fclose($fh);
  6. unlink('/var/tmp/foo.bar')
  7. unlink($file_path)
foo.bar disappeared but the other file did not.
Jan 10 '08 #2
6,050 Recognized Expert Expert
The file which is executing unlink() has to be in the same directory as the file being deleted :)
Jan 10 '08 #3
314 Contributor
The file which is executing unlink() has to be in the same directory as the file being deleted :)
But I can delete other files in that directory.. just not the one that gets sent to the user.

I'm thinking the only way around this will be to update to postgresql 8.2 so that I will not need to generate a temporary file... either that or make a cron job to clear the .csv files from that directory every day.
Jan 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Eric | last post by:
Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a MySql database. The upoaded file itself is stored in a directory called "files". With an administration form I can read all contents of the data.dat file and select records to delete (one at a...
by: Chamomile | last post by:
I am having trouble getting unlink() to work on my local machine (win 2000, Apache, php 4.2.2) when I invoke unlink() in order to change a file name during a 'picture edit' change from a form upload on my local machine using simple stuff like: <?php if(file_exists($new_file_name)){
by: ORC | last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ??? Thanks Ole
by: nitinpatel1117 | last post by:
Hi I am trying to delete a csv file using the unlink() function, but i keep getting a permission denied warning Warning: unlink(UsedNOS200704191.CSV): Permission denied in E:\webroot\dev\file_test\index.php on line 416 My script basically reads email attachments and downloads the attachment file into the current directory of the running...
by: Eric Renken | last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't working for me. The WaitForSingleObject keeps giving me an error "The system cannot find the file specified." This code need to work in 64bit and 32bit, so I am using IntPtr for pointers instead of int. Here is the structure of OVERLAPPED public struct...
by: huiling25 | last post by:
I don't know why the customer records cannot be inserted into the linked list and the head of the linked list keep pointing to null... //ListNode.java public class ListNode{ private Object item; private ListNode next,head; public ListNode(Object newItem) { item = newItem; next = null; } public ListNode(Object...
by: fcaserio | last post by:
Is there any PHP.INI config or windows permission (win 2003) that can prevent PHP to unlink files with the system path? unlink works with relative path: @unlink("temp\0000058.txt") but it is not workinng with the absolute path @unlink("C:\htdocs\temp\0000058.txt") the thing is I use unlink within a function called from different...
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo "$filename <br>". "<a href="unlink('$filename');">Delete</ a>";
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.