Php-mysql Course

Simple PHP function that can be used to read data of a ZIP archive with PHP. The function receives a string with the path-name of the Zip file; and returns a two dimensional Array with data of each file in archive (name, actual_filesize, compressed_size).
<?php
// Function to Read ZIP Archive. Returns a two dimensional Array with data of each file in archive
function readZipData($zip_file) {
  // PHP-MySQL Course - https://coursesweb.net/php-mysql/
  $zip_data = array();     // will store arrays with data of each file in archive
  $zip = zip_open($zip_file);

  // if the $zip_file is opened, traverse the archive
  if($zip) {
    while ($zip_entry = zip_read($zip)) {
      // adds in $zip_data an array with data of each file in archive
      $zip_data[] = array(
        'name' =>zip_entry_name($zip_entry),
        'actual_filesize' => zip_entry_filesize($zip_entry),
        'compressed_size' => zip_entry_compressedsize($zip_entry)
      );
    }
    zip_close($zip);

    return $zip_data;
  }
  else  echo "Failed to open $zip_file";
}

  /* Example */

//the path-name of the zip file
$zip_file = 'dir/file.zip';

// get data of the $zip_file
$zip_data = readZipData($zip_file);

// output the resulted array (with data for archived files)
echo '<pre>';
var_export($zip_data);
echo '</pre>';
?>
This example will return an array like this:
array (
  0 => 
  array (
    'name' => 'file1.txt',
    'actual_filesize' => 388984,
    'compressed_size' => 114339,
  ),
  1 => 
  array (
    'name' => 'image.jpg',
    'actual_filesize' => 16942,
    'compressed_size' => 16801,
  ),
  2 => 
  array (
    'name' => 'audio/music.mp3',
    'actual_filesize' => 16942,
    'compressed_size' => 16806,
  )
)

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
Read ZIP archive data with PHP

Last accessed pages

  1. Insert, Select and Update NULL value in MySQL (59216)
  2. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (143287)
  3. Image in PHP with background in two colors (1238)
  4. AJAX Course, free Lessons (19946)
  5. Working with XML Namespaces in ActionScript (2997)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (520)
  2. CSS cursor property - Custom Cursors (69)
  3. The Mastery of Love (50)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (48)
  5. Read Excel file data in PHP - PhpExcelReader (46)