mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
add method to test existing and at first look valid zip file
This commit is contained in:
parent
c64b972564
commit
f8aeb57582
@ -44,11 +44,11 @@ class Files
|
|||||||
* @param string $filename Path to target zip file.
|
* @param string $filename Path to target zip file.
|
||||||
* @param string $path Directory to be zipped.
|
* @param string $path Directory to be zipped.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return integer The number of files added to the zip file.
|
||||||
*/
|
*/
|
||||||
public static function zip(string $filename, string $path)
|
public static function zip(string $filename, string $path)
|
||||||
{
|
{
|
||||||
// Generate a collections zip for Metaconsole.
|
$added_files = 0;
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
$zip->open(
|
$zip->open(
|
||||||
$filename,
|
$filename,
|
||||||
@ -82,6 +82,7 @@ class Files
|
|||||||
|
|
||||||
// Add current file to archive.
|
// Add current file to archive.
|
||||||
$zip->addFile($filePath, $relativePath);
|
$zip->addFile($filePath, $relativePath);
|
||||||
|
$added_files++;
|
||||||
|
|
||||||
// Keep file permissions.
|
// Keep file permissions.
|
||||||
$zip->setExternalAttributesName(
|
$zip->setExternalAttributesName(
|
||||||
@ -93,6 +94,31 @@ class Files
|
|||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
|
return $added_files;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if given file is zip file.
|
||||||
|
*
|
||||||
|
* @param string $file File.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function testZip(string $file):bool
|
||||||
|
{
|
||||||
|
if (file_exists($file) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zip = new \ZipArchive;
|
||||||
|
if ($zip->open($file, (\ZipArchive::RDONLY & \ZipArchive::ER_READ)) === true) {
|
||||||
|
$zip->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user