SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    zip file, extractTo

    Hi, I have one zip with files in different folders:

    Code:
    test.zip
    /dira/file1.xml
    /dirb/file2.xml
    I´m trying to extract one of those files:

    Code:
    ...
    $z->extractTo("/dest_path/", "/dira/file1.xml");
    but it doesn´t work.

    If I use a zip without folders, everything work correctly

    any idea?

    thanks.

  2. #2
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problems may arise in “$z->extractTo” here, I don‘t know how your other code is written?

  3. #3
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    the rest of code is:

    Code:
    $z = new ZipArchive();
    $z->open('file.zip');
    $z->extractTo("/dest_path/", "/dira/file1.xml");
    thanks for your help

  4. #4
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I´ve seen a few examples, and it seems to be correct.

    Maybe the first "/" in the zip path must be deleted.

    Code:
    wrong? $z->extractTo("/dest_path/", "/dira/file1.xml");
    
    correct? $z->extractTo("/dest_path/", "dira/file1.xml");
    I´ll try later at home (I can´t check it at job)

  5. #5
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, the first problem was "/"

    then, it works
    Code:
    $z->extractTo("/dest_path/", "dira/file1.xml");
    the problem is that it creates dira and extract file1.xml inside of it.

    But I want to extract file1.xml ti dest_path folder

    any idea?

    thanks!

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    EU/UK+DK
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having glanced at the ZIP manual entry, I suspect what you want is ZipArchive::getStream().

    A modified version of the example given on the ZipArchive::getStream manual page (assuming >= PHP 5 for file_put_contents):
    PHP Code:
    // Customise as required.

    $content '';
    $z = new ZipArchive();
    if ( 
    $z->open('file.zip') )
    {
        
    $fp $z->getStream('dira/file1.xml');
        if ( !
    $fp )
        {
            exit(
    'failed');
        }
        while ( !
    feof($fp) )
        {
            
    $contents .= fread($fp2);
        }
        
    fclose($fp);
        
    file_put_contents('/dest_path/file1.xml',$contents);
        echo 
    'done';

    That should get you going in the right direction.
    The plus sign (+) is valid within an email address; please do not
    write or suggest code that precludes its use, as many use it as a
    "label" to filter incoming mail. </crusade>

  7. #7
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it works correctly

    thanks very much!


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
  •