PDA

View Full Version : This is a tough one.



conozco345
07-15-2002, 07:34 AM
Alright. I am trying to either create or find a script in which you can zip uploaded files. What I mean exactly, is instead of users visiting my site and downloading and extracting files one at a time, the select the files they want to download and those files are added to a zip file in which the user can download. After that takes place, depending on how the script runs, if it actually creates a new file to the directory, I want it to detect when the download is finished and to delete the file once its complete. If anyone can help me out on this, then you are a god at java script. Thanks!

premshree
07-15-2002, 08:11 AM
That's a really tough one! You cannot do that in client-side JavaScripting. Possible using server-side but still a tough one.

:confused:

Dalsor
07-15-2002, 09:11 AM
This is possible with PHP. Just off the top of my head, not tested or anything, so more than likely will not work as is, but will work with some tweaking. :)



// little array
$file[0] = 'file0.txt'
$file[1] = 'file1.txt'

// set the variables
$maxFiles = count( $file );
$i = 0; // I don't think you have to pre-define variables like this in PHP

// loop and zip the files
for ( $i = 0; $i < $maxFiles; $i++ )
{
$fname = $file[i];
// could also use tar-gzip in a similar fashion
exec( "zip -g file.zip $fname" );
}


To do this the way you have described, you'll likely want to make an array of checkboxes or something of that nature. 'Check the box next to each file you wish to download...' kind of deal using a form to catch the variables, then calling the PHP function on submit.



if ( isset( checkBoxArray[0] ) )


If this helps in any way, it'll be the first time I've been able to contribute something back to these forums. :thumbsup:

Dalsor
07-15-2002, 09:19 AM
Er, forgot... to delete the file, unlink it. Basic Unix C command.

unlink ( $zipFile );

If your webhost or server is Windows based, use system if unlink doesn't work.

system( "del \"$zipFile\"" );

chrisvmarle
07-15-2002, 10:28 AM
Originally posted by Dalsor



// could also use tar-gzip in a similar fashion
exec( "zip -g file.zip $fname" );



Does this work on my Win98 system? And how about my WinXP?

I can't git it to work, seems like I don't have an executable named zip(.exe). What do I need to do? (Except for looking for a *nix host ;))

Mzzl, Chris

Dalsor
07-15-2002, 10:56 AM
I'm going to hope that someone who is more eXPerienced with Windows will step in here. :)

Exec is a standard (glibc) C lib call, which I assumed would be pretty universal with PHP4 since many of the functions are similar, if not the same. I am far removed from a Windows programmer, though, so I can't say for certain how MS has employed/adapted/(quote)improved(/quote) it.

Zip itself is part of PKWare's pkzip/pkunzip library (generally? I understand there are various packages which support .zip as a standard; that dates my knowledge of zip to maybe 20 years ago on DOS systems ). As far as I know, they have fully functionaly 16/32 bit versions of these libs, so it should just be a matter of installing what you need onto your host. From your post, I'm guessing you're running your own host via a WinXP system? (If wrong, please correct.) If so, include in your PATH statement the location of the zip libraries so that a call to zip can find it no matter where the .exe is located.

In short, make sure you have a suitable handler for a .zip file on your system, be it pkzip/pkunzip for Windows(95-98) and plain-jane zip for *nix, and in the Windows case, make sure your PATH statement reflects the location of the .exe

Dalsor
07-15-2002, 11:06 AM
Another Er, try using system(); for Windows systems...

chrisvmarle
07-15-2002, 12:23 PM
Thanks for all the information, I'll try to find a suitable programme.

Thanks;
Mzzl, Chris

firepages
07-15-2002, 12:27 PM
Hi, exec works on win32 as well, there are some command line zip utilities perhaps google that?

note you can also use PHP's gzip functionality to create gzipped files or there is even a class for creating zip files on the fly

http://www.firepages.org/public/zipfile.php.txt

conozco345
07-15-2002, 05:51 PM
thanks I just read the replys. I'll try tweaking it and if it works i'll let you know... If so you should submit it to javascriptkit.com and other places because its really useful! Thanks! :)