Re: Logic sought

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
Hi gang:

Here's the logic problem.

First the site:

http://php1.net/b/zip-files/

Now, the site works well enough. The user selects what they want, clicks Submit, the order is assembled in zip file and presented to the user for downloading.

However, as it stands now, before the script assembles the test.zip, it deletes (unlinks) the previous test.zip and therein lies the problem.

If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all.

The complicated way I figure I could solve this would be to:

1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip.

2. Then when the user selects the download that would trigger a javascript routine that would send the name of the file to be deleted to a slave php script that would unlinks the file.

I know this will work, but if the user never downloads the file, then the files accumulate on the server.

Does anyone have a better idea?

Thanks,

tedd


For bespoke downloads I create a directory somewhere named with the session ID, then build the download file there and only allow access throw a PHP script which knows the session ID. I guess it depends how commercial or sensitive the data is.
Then I have a cron or something clean up the old directories.

It would be nice to have some sort of trigger to indicate that the session has expired - anyone know if Apache can do such a thing? In a Java environment, I used a session object which cleaned up such folders when it was garbage-collected...

--
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux