Results 1 to 12 of 12

Thread: Unzip with PHP

  1. #1

    Unzip with PHP

    Hi All,

    I have faced quite an interesting problem.Following is what I want to do:

    My script(which is in my server runs every night as a cron job) connects to a remote server and gets .zip file . Now this .zip file has got password and nneds to unzip by the script, and then another perser will perse the file and undate the database.

    I think can use system command to unzip it, but don't know how to use it or rather whetn you have a password protected .zip file.

    Can anyone throw some light on it?

    I appreciate your reading by and welcome any help.

    Regards
    Krishnendu

  2. #2
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    4,695
    You can just use the shell command "unzip file.zip" or if you want to stick to a php based script have a look at zziplib http://zziplib.sourceforge.net but i'm quite sure there's no way to extract a pass-protected archive.

  3. #3
    Hi Loon,

    I had a look at zziplib, but thats not installed in my client server....so I looked at m-zip http://esurfers.com/m-zip/...

    But it fails....

    Another interesting point is when I run an system command like
    system('unzip $file',$ret_val)
    I am getting a $ret_value of 0, which means that unzip is successful(as per info-zip.org), but there is no unzipped folder or file created....

    Btw is there any other way of doing it like with .net or any other language?

    Thanks for reading by and your comments
    Krishnendu

  4. #4
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    4,695
    I did see an unzip class on zend.com once i think.

  5. #5
    Join Date
    Jul 2002
    Location
    UK
    Posts
    2,026
    robertson, normally 0/false is unsuccessful and 1/true is successful. maybe unzip is different though?

    you could try putting:

    echo `unzip file.zip`;

    into a script and seeing what it outputs, though.
    Gone.

  6. #6
    Hi Loon,

    I had look into different unzip class, but the problem is none supports password protected files.

    Hi Phision,

    I will try out today your advise...let see what happens...

    Anyone with any other idea.....may be any other scripting language?

  7. #7
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    4,695
    Originally posted by robertson
    the problem is none supports password protected files.
    no, like i said, i'm quite sure it isn't possibile.

  8. #8
    Join Date
    Feb 2004
    Posts
    60
    Hi,

    try the following command

    unzip -P password file.zip

  9. #9
    Whats the point of encrypting it?

    #1) Can easily be broken
    #2) You have to supply the password in PLAINTEXT to zip it.
    #3) You have to supply the pass in PLAINTEXT to unzip it.

    Think about what you are doing here...
    "The only difference between a poor person and a rich person is what they do in their spare time."
    "If youth is wasted on the young, then retirement is wasted on the old"

  10. #10
    Hi innova,

    I have no control over the putting password in the .zip file..its done by some authority...if had a control over it...then I wouldn't have put the password...and there wouldn't be any problem..isn't it?

    anyway...the problem is solved....And It can be done....you can unzip a password protected file with PHP in Unix....(I haven't tested it in Windows..or any other platform)...run the following system command....

    system("`which unzip` -P Password $pathtozipfle -d $destinationdir",$ret_val)....

    if everything runs properly you will get back 0 for $ret_val..which means complete success.(info-zip.org)

  11. #11
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    1 usually means success, not 0.

    You should check the return value of system() also.

    Returns the last line of the command output on success, and FALSE on failure.
    http://www.php.net/system
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  12. #12
    Hi fyrestrtr,

    I know usually 1 means success, but unix based system generally use http://www.info-zip.org modules for zip and unzip functions. And as per them 0 means complete success and 1 means .zip file to be unzipped could not be found...I tested the returns values for 1 as well..and seen that its means .zip file could not be found and hence it was not unzippped...

    Please refer http://www.info-zip.org for more details...

    Regards
    Krishnendu

Posting Permissions

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