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).
// Function to Read ZIP Archive. Returns a two dimensional Array with data of each file in archive
function readZipData($zip_file) {
  // PHP-MySQL Course -
  $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)

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

  /* Example */

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

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

// output the resulted array (with data for archived files)
echo '<pre>';
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

Which HTML5 tag is indicated to be used as container for menu with navigation links in Web site?
<section> <nav> <article>
 <li><a href="" title="CSS Course">CSS Course</a></li>
 <li><a href="" title="Flash Games">Flash Games</a></li>
Which CSS property shifts an item horizontally to the left or right of where it was?
text-align clear float
.some_class {
  width: 30%;
  float: left;
Click on the Math object method which returns x, rounded downwards to the nearest integer.
Math.ceil(x) Math.abs(x) Math.floor(x)
var num = 12.34567;
num = Math.floor(num);
alert(num);       // 12
Indicate the PHP function which returns the number of characters in string.
mb_strlen() count() stristr()
$str = "string with utf-8 chars åèö";
$nrchr = mb_strlen($str);
echo $nrchr;        // 30
Read ZIP archive data with PHP

Last accessed pages

  1. Execute JavaScript scripts loaded via AJAX (5460)
  2. Simple arithmetic calculator in PHP (784)
  3. JavaScript Chronometer / Stopwatch (6101)
  4. SHA256 Encrypt hash in JavaScript (13835)
  5. Ajax-PHP Chat Script (44985)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (491)
  2. Read Excel file data in PHP - PhpExcelReader (228)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (218)
  4. querySelector and querySelectorAll (209)
  5. Create simple Website with PHP (199)