SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Zip...

Hybrid View

  1. #1
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zip...

    Hello

    If I have a zip file located at on the hard drive, how do I extract the files from it to a specific location with php?

    And while I'm at it I'd like to congratulate Sitepoint for the new web!

    Thanks in advance!
    Last edited by website; Feb 24, 2003 at 15:26.
    - website

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have the proper module installed and PHP 4.1.x or better you can use:

    http://www.php.net/manual/en/function.zip-open.php

    Otherwise, you may find some sample code at zend.com or phpclasses.org which work without special modules.

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, well, I already checkt out these functions but I just don't know how to actually write the files to the harddrive.?
    - website

  4. #4
    SitePoint Addict Clete2's Avatar
    Join Date
    Mar 2002
    Location
    Columbia, South Carolina
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to try using exec("cp (or copy, depending on your OS) X:\...\file.zip X:\...\( depending on your OS, again, you may have to put to.zip)")
    My Blog
    My Photography Website
    Linux user #339185

  5. #5
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your replys but I don't think you understand what I have in mind.
    Say I have a zip file called images.zip
    In that file are say 3 files, image1.jpg, image2.jpg, image3.jpg.

    The user uploads the file, I get the path to the temp file, I place it in a variable called $filetmp

    Then I want to take each entry (image1.jpg, image2.jpg, image3.jpg) and save it to
    wwwroot/images/
    And then the zip file should be destroid (or just something)

    I can't use move_uploaded_file (I think) or use Clete's suggestion because the images are inside the zip file. So how would I move image1.jpg to the predefined location?

    Thanks in advance!
    Last edited by website; Feb 26, 2003 at 16:59.
    - website

  6. #6
    SitePoint Addict Clete2's Avatar
    Join Date
    Mar 2002
    Location
    Columbia, South Carolina
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, sorry... I misunderstood. I thought you wanted to copy it to another location... again you will need exec() unless I'm missing a function... save the file, then try:

    PHP Code:
    <?php
     
    exec
    ("unzip "$filename);
    exec("unlink "$filename);
     
    ?>
    Works for me ... I'll look into one that does not need exec...

    I found this, though:

    http://www.zend.com/zend/spotlight/...-zip-files1.php
    http://www.zend.com/zend/spotlight/...-zip-files2.php
    http://www.zend.com/zend/spotlight/...-zip-files3.php
    My Blog
    My Photography Website
    Linux user #339185

  7. #7
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Clete2
    PHP Code:
    <?php
     
    exec
    ("unzip "$filename);
    exec("unlink "$filename);
     
    ?>
    Hmm, I tryed it and there came no error, that at least is good sign. But how can I then move the files, I mean, you unzip it, then what? how would I save the files to some location? All advice or hints in the right direction I apreciate very much!
    - website

  8. #8
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, not quite getting this, exec, doesn't it just execute some commands on the os command line?

    But there are some functions like zip_open zip_read but I just don't know how to acctually save each entry to the hard drive

    And that Zend article is quite nice... except that they are doing the opposite of what I want
    - website


Bookmarks

Posting Permissions

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