Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation This is a tough one.

    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!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's a really tough one! You cannot do that in client-side JavaScripting. Possible using server-side but still a tough one.


  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Florida, USA
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    // 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.

    PHP Code:
    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.

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    Florida, USA
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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\"" );

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Dalsor

    PHP Code:
      // 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

  • #6
    New Coder
    Join Date
    Jul 2002
    Location
    Florida, USA
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    New Coder
    Join Date
    Jul 2002
    Location
    Florida, USA
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another Er, try using system(); for Windows systems...

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all the information, I'll try to find a suitable programme.

    Thanks;
    Mzzl, Chris

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    Registered User
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •