SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file extension change n zip file read

    Earlier I was saying about phone theme .nth .

    1. How can I change the file extention from text.nth to .text.zip using php?

    2. I managed this code which does not work to read files inside a zip.file so it does not echo.

    PHP Code:
    <?php
    $zip 
    zip_open("test.zip");

    if (
    $zip)
      {
      while (
    $zip_entry = @zip_read($zip))
        {
        echo 
    "<p>";
        echo 
    "Name: " zip_entry_name($zip_entry) . "<br />";
        if (
    zip_entry_open($zip$zip_entry))
          {
          echo 
    "File Contents:<br/>";
          
    $contents zip_entry_read($zip_entry);
          echo 
    "$contents<br />";
          
    zip_entry_close($zip_entry);
          }
        echo 
    "</p>";
      }

    @
    zip_close($zip);

    }
    ?>
    Could anyone please fix it?
    Last edited by coolR; Oct 18, 2008 at 17:46.

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any help please?

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try this CoolR:-
    PHP Code:
    <?php
    //--> Rename file.
    rename('sample.nth','sample.zip');
    //--> Open the Zip Archive
    $oZip = new ZipArchive();
    $oZip->open('sample.zip');
    for ( 
    $i $i <= $oZip->numFiles $i++ )
    {
        
    //--> $aFile is an array which holds all this files information.
        
    $aFile $oZip->statIndex($i);
        echo 
    $aFile['name'] . '<br />';
    }
    ?>
    Zip Documentation
    Rename Documentation
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    silver thanks a lot for informing rename()

    I am very bad in OOP but as far as I understand that the ZipArchive() is missng here.

    In my code I added @ before zip_read() and zip_close() to ignore showing this kind of error message

    Warning: zip_read() expects parameter 1 to be resource, integer given in xxxxxx on line x

    but this zip_read() is working like fread()

    How can I sort out files within a zip file using PHP ?

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    zip_open returns an Integer when it cannot open the file, make sure you have the FULL path to the target zip passed to the function.

    Try this:-
    PHP Code:
    <?php

    $zip 
    zip_opengetcwd() . DIRECTORY_SEPARATOR "sample.zip");

    if (
    is_resource($zip))
    {
        while (
    $zip_entry zip_read($zip)) {
            echo 
    "Name:               " zip_entry_name($zip_entry) . "<br />";
            echo 
    "Actual Filesize:    " zip_entry_filesize($zip_entry) . "<br />";
            echo 
    "Compressed Size:    " zip_entry_compressedsize($zip_entry) . "<br />";
            echo 
    "Compression Method: " zip_entry_compressionmethod($zip_entry) . "<br />";
            if (
    zip_entry_open($zip$zip_entry"r")) {
                
    $sBuffer zip_entry_read($zip_entryzip_entry_filesize($zip_entry));
                
    file_put_contents(zip_entry_name($zip_entry),$sBuffer);
                
    zip_entry_close($zip_entry);
            }
        }
        
    zip_close($zip);
    }
    else
    {
        die(
    'Failed to open Zip file!');
    }

    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried several times with
    $zip = zip_open( getcwd() ."/sample.zip");
    and
    $zip = zip_open( getcwd() . "\sample.zip");

    None of them works


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
  •