473,507 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete file after headers sent


Hi guys,

Is there any way how to delete a file after download headers have been
sent? This code does not work for some reason.

header('Content-type: application/xml');
header('Content-Transfer-Encoding: binary');
header('Content-length: '.filesize($f));
header('Content-Disposition: attachment; filename="'.basename($f).'"');

if($fp = fopen($f, "rb"))
{
while ($buffer = fread($fp, filesize($f))) print $buffer;
fclose($fp);
}

unlink($f);
--
Collector
------------------------------------------------------------------------
Collector's Profile: http://techiegroups.com/member.php?userid=264
View this thread: http://www.techiegroups.com/showthread.php?t=115692

Sep 1 '06 #1
5 5144
You may need to CHMOD the file (and possibly the containing folder) to
be writable by the script.

Collector wrote:
Hi guys,

Is there any way how to delete a file after download headers have been
sent? This code does not work for some reason.

header('Content-type: application/xml');
header('Content-Transfer-Encoding: binary');
header('Content-length: '.filesize($f));
header('Content-Disposition: attachment; filename="'.basename($f).'"');

if($fp = fopen($f, "rb"))
{
while ($buffer = fread($fp, filesize($f))) print $buffer;
fclose($fp);
}

unlink($f);
--
Collector
------------------------------------------------------------------------
Collector's Profile: http://techiegroups.com/member.php?userid=264
View this thread: http://www.techiegroups.com/showthread.php?t=115692
Sep 1 '06 #2
Collector wrote:
>
Hi guys,

Is there any way how to delete a file after download headers have been
sent? This code does not work for some reason.

header('Content-type: application/xml');
header('Content-Transfer-Encoding: binary');
header('Content-length: '.filesize($f));
header('Content-Disposition: attachment; filename="'.basename($f).'"');

if($fp = fopen($f, "rb"))
{
while ($buffer = fread($fp, filesize($f))) print $buffer;
fclose($fp);
}

unlink($f);

Can you unlink the file anyway?
I seriously doubt the headers are influencing this...

Regards,
Erwin Moller
Sep 1 '06 #3

Thanks guys. Nope, it has nothing to do with permissions. I am able to
unlink the file with no problem. After sending download headers it
looks like PHP can execute only the next line (reading and sending out
the file) but nothing else. I was just wondering if there is some
workaround leading to successful deletion of a file after headers of
this type have been sent. Thanks.
--
Collector
------------------------------------------------------------------------
Collector's Profile: http://techiegroups.com/member.php?userid=264
View this thread: http://www.techiegroups.com/showthread.php?t=115692

Sep 1 '06 #4
Collector wrote:
Thanks guys. Nope, it has nothing to do with permissions. I am able to
unlink the file with no problem. After sending download headers it
looks like PHP can execute only the next line (reading and sending out
the file) but nothing else. I was just wondering if there is some
workaround leading to successful deletion of a file after headers of
this type have been sent. Thanks.

As Erwin indicated - headers should have nothing to do with this. You
should be able to unlink the file with no trouble.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 1 '06 #5
*** Collector escribió/wrote (Fri, 1 Sep 2006 02:49:22 -0400):
while ($buffer = fread($fp, filesize($f))) print $buffer;
Depending of the size of your file, this can make your script run our of
memory and crash, so you after that won't be able to remove the file... or
print "hello word". Try readfile() or, simply don't use the full file size
as buffer size. Actually, I can't see the point of a while loop that's
supposed to be run once.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
21045
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
11
912
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
16
16975
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
5353
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
9
1503
by: comp.lang.php | last post by:
<?php if (headers_sent()) print_r('headers sent'); // do other stuff ?> I have a file, "classes.inc.php", a library of PHP version 4+ classes. This library file, the moment it is included,...
4
1750
by: Brad | last post by:
I have a file that downloaded a CSV file for the user based upon some information gathered from the Database. My file was working fine until recently (I believe that my hosting company did...
6
7314
by: john | last post by:
The standard method to transmit a file from an aspx page to a browser is to stream the file to the response then end the response. The HTML code generated by the aspx page is discarded, and the...
0
928
by: bruce | last post by:
hi jackie, if you don't mind... can i ask what you're looking to accomplish? are you looking to simply get the text/string data, or something else??? -----Original Message----- From:...
1
1337
by: DavidPr | last post by:
I'm using the delete script below. It's deleting and sending the email OK, but the correct information is not being sent. I tested this script on one database and it deleted several ads, but the...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
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...
1
7034
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...
0
7488
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
5623
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,...
0
4702
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.