KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to unzip file using php
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: July 17, 2015

Create a php script with the following function:

<?php
function unzip($p1,$p2) {
  $zip = new ZipArchive;
  if ($zip->open($p1) === TRUE) {
    $zip->extractTo($p2);
    $zip->close();
    return 'success';
  } else {
    return 'failed';
  }
}
?>


In 4D, the function "unzip" can be ran using php execute:
C_TEXT($sourcePath;$destPath;$scriptPath)
C_TEXT($return)
C_BOOLEAN($res)

//Path of zip file
$sourcePath:=Get 4D folder(Database folder)+"Resources"\
  +Folder separator+"myFiles.zip"

//Path to destination path
$destPath:=Get 4D folder(Database folder)+"Resources"+Folder separator

//Path to php script
$scriptPath:=Get 4D folder(Database folder)+"php"+Folder separator+"extract.php"

$res:=PHP Execute($scriptPath;"unzip";$return;$sourcePath;$destPath)