By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,374 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,374 IT Pros & Developers. It's quick & easy.

Strategy for creating files and then cleaning up

P: n/a
Hi,

I'm using PHP 4.3. There is a section of my application in which I'd
like users to be able to download a custom file. The file would be
different for each user, so I was planning on creating it on the fly
when they click "Download". However, I would like to delete the file
from the server a certain period of time after they've downloaded it.
(It's a 3 or 4K file). How can I do this?

Thanks, - Dave

Jul 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.3. There is a section of my application in which I'd
like users to be able to download a custom file. The file would be
different for each user, so I was planning on creating it on the fly
when they click "Download". However, I would like to delete the file
from the server a certain period of time after they've downloaded it.
(It's a 3 or 4K file). How can I do this?

Thanks, - Dave
Hi Dave,

This can be done in several way, but why do you actually create the file?
You can also just give the user the experience there is a file when (s)he
clicks the downloadbutton.
Just let the download-php-script produce the output, just as you do before
writing the file, and deliver that.

If that doesn't work for you for some reason, and you absolutely need to
create a real file, you can do several things to clean them up, the most
easy:
- Create a sheduled job (cron on *nix) that checks all possible files and
check their createdate. If too old, delete.

Alternatively to a sheduled job, you could use an approach that will do this
once every 100 times your function is called that creates the file.
Or every time, but this may get slow if you have a great numbers of files.

Regards,
Erwin Moller
Jul 3 '06 #2

P: n/a
Rik
la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.3. There is a section of my application in which I'd
like users to be able to download a custom file. The file would be
different for each user, so I was planning on creating it on the fly
when they click "Download". However, I would like to delete the file
from the server a certain period of time after they've downloaded it.
(It's a 3 or 4K file). How can I do this?
filemtime() could be used for this.

However, if your file is made dynamically, and downloaded only by a specific
user, is there any reason to save it as a file to begin with? With proper
headers and PHP output you can just dynamically create/'fake' the file each
time it is required, without having to save it, track it, and clean it up.

Grtz,
--
Rik Wasmus
Jul 3 '06 #3

P: n/a
I want the users to download a file with an ".html" extension. What
kind of headers would I use to save creating that on a server and have
that downloaded right to the Desktop (or whereever their default save
location is)?

Thanks, -

Rik wrote:
la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.3. There is a section of my application in which I'd
like users to be able to download a custom file. The file would be
different for each user, so I was planning on creating it on the fly
when they click "Download". However, I would like to delete the file
from the server a certain period of time after they've downloaded it.
(It's a 3 or 4K file). How can I do this?

filemtime() could be used for this.

However, if your file is made dynamically, and downloaded only by a specific
user, is there any reason to save it as a file to begin with? With proper
headers and PHP output you can just dynamically create/'fake' the file each
time it is required, without having to save it, track it, and clean it up.

Grtz,
--
Rik Wasmus
Jul 3 '06 #4

P: n/a
*** la***********@zipmail.com escribió/wrote (3 Jul 2006 13:41:15 -0700):
I want the users to download a file with an ".html" extension. What
kind of headers would I use to save creating that on a server and have
that downloaded right to the Desktop (or whereever their default save
location is)?
header('Content-Type: text/html');
header('Content-Length:' . filesize(........));
header('Content-Disposition: attachment; filename="..........."');

Another option:

header('Content-Type: application/octet-stream');
--
-+ 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
--
Jul 3 '06 #5

P: n/a
la***********@zipmail.com wrote:
Hi,

I'm using PHP 4.3. There is a section of my application in which I'd
like users to be able to download a custom file. The file would be
different for each user, so I was planning on creating it on the fly
when they click "Download". However, I would like to delete the file
from the server a certain period of time after they've downloaded it.
(It's a 3 or 4K file). How can I do this?

Thanks, - Dave
Think a few have pointed this out, but you don't need to store the
file, something like:

header('Content-Type: text/html');
header('Content-Length:' . filesize(........));
header('Content-Disposition: attachment; filename="..........."');
// Display what you want to output
print "Something, Or, Other, just testing, the way this works";
// Output a new line else everything is all on one line.
print "\n";
print "www.whatever.co.uk";
print "\n";
Obviously the script can be changed for each user using a little php.

I've a collection of useful scripts on a site I put together (nothing
major, just slowly collecting together things i've written over the
years).
http://www.opanoid.co.uk/phphelp/

C Wood.

Jul 3 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.