473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

PHP unable to unlink after readfile()

jlm699
314 100+
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';
  2.  
  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. ?>
  12.  
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 4756
jlm699
314 100+
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);
  5.  
  6. unlink('/var/tmp/foo.bar')
  7. unlink($file_path)
  8.  
foo.bar disappeared but the other file did not.
Jan 10 '08 #2
Markus
6,050 Expert 4TB
The file which is executing unlink() has to be in the same directory as the file being deleted :)
Jan 10 '08 #3
jlm699
314 100+
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

2
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...
1
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...
12
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
4
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...
4
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...
3
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...
1
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...
15
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...
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.