Page 1 of 1

Downloading an entire folder

Posted: Mon Mar 01, 2010 12:26 pm
by jateeq
Hello,

I was wondering how one downloads an entire folder through php. I am planning on

- creating a tarball once a user clicks on the download link
- store this tarball wherever the uncompressed folder is located
- force download this tarball
- delete this tarball once the process is complete

Is this the right way of doing it? I don't see a problem with this, but then again, I don't see a problem with most things until they turn on me :banghead: .

Thanks.
Jawad.

Re: Downloading an entire folder

Posted: Mon Mar 01, 2010 12:35 pm
by requinix
I'd pick one spot to store all the archives (temporarily) but keep them there for a while after the download completes. Maybe the connection dropped in the middle of the transfer and the user needs it again?

Then put the archive name and date in a database and periodically check for old files to delete.

Re: Downloading an entire folder

Posted: Mon Mar 01, 2010 2:03 pm
by jateeq
I don't want to store these files in a database (i don't want to maintain the database and I don't want to spend time learning sql).
How about using linux's find function to list the last time the file was accessed, and then delete it if it's old enough? Are there any advantages to using databases?

Thanks.
Jawad.

Re: Downloading an entire folder

Posted: Mon Mar 01, 2010 2:24 pm
by requinix
You best start learning SQL if you want to go anywhere as a web developer. There are so many uses for a database I couldn't possibly list even the most important ones.

I'm not saying store the entire tarball in the database - just the name and date it was created. Searching the database is easy and, most importantly, operations are essentially atomic.
Situation: you have two scripts running at the same time. Call them A and B. A searches for old tarballs. B searches for old tarballs. A finds an old one and deletes it. B finds the same old one and tries to delete it - but can't since A already did. Properly done, that never happens with a database.