Better error management for dol_uncompress
This commit is contained in:
parent
e6c9e07de4
commit
afecab3f39
@ -1261,18 +1261,39 @@ function dol_compress_file($inputfile, $outputfile, $mode="gz")
|
|||||||
*/
|
*/
|
||||||
function dol_uncompress($inputfile,$outputdir)
|
function dol_uncompress($inputfile,$outputdir)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (defined('ODTPHP_PATHTOPCLZIP'))
|
if (defined('ODTPHP_PATHTOPCLZIP'))
|
||||||
{
|
{
|
||||||
|
dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".constant('ODTPHP_PATHTOPCLZIP').", so we use Pclzip to unzip into ".$outputdir);
|
||||||
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
||||||
$archive = new PclZip($inputfile);
|
$archive = new PclZip($inputfile);
|
||||||
if ($archive->extract(PCLZIP_OPT_PATH, $outputdir) == 0) return array('error'=>$archive->errorInfo(true));
|
$result=$archive->extract(PCLZIP_OPT_PATH, $outputdir);
|
||||||
else return array();
|
//var_dump($result);
|
||||||
|
if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ok=1; $errmsg='';
|
||||||
|
// Loop on each file to check result for unzipping file
|
||||||
|
foreach($result as $key => $val)
|
||||||
|
{
|
||||||
|
if ($val['status'] == 'path_creation_fail')
|
||||||
|
{
|
||||||
|
$langs->load("errors");
|
||||||
|
$ok=0;
|
||||||
|
$errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ok) return array();
|
||||||
|
else return array('error'=>$errmsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists('ZipArchive'))
|
if (class_exists('ZipArchive'))
|
||||||
{
|
{
|
||||||
|
dol_syslog("Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
$res = $zip->open($inputfile);
|
$res = $zip->open($inputfile);
|
||||||
if ($res === TRUE)
|
if ($res === TRUE)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user