473,767 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP unable to unlink after readfile()

jlm699
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';
  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 4796
jlm699
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);
  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 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
jlm699
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

2
6697
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 time). So far so good.
1
2800
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)){
12
6901
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
12831
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 script. The data in the attachements is then read and stored into MySQL. Once i've finished reading...
4
13990
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 OVERLAPPED
3
4207
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 newItem, ListNode newNext) { item = newItem; next = newNext; } public void...
1
2499
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 directories, so I use absolute path to make sure the path is correct. I've installed my application on...
15
3772
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>";
18
14644
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.