the below function do, to extract a zip folder to a directory after that zipped folder needs to move to another folder.
It is working some times and not working some times, probability of working function is very low. Hence, i would like to seek your help to optimize and suggest this function should in any kind of environment, it should be independent of operation system.
function extractTo(){
//This will extract project directory to fetch installable version of TV APP.
$path='../';
$filename = 'xyz-v1.22.zip';
$zipname = $path.$filename;
$zip = new ZipArchive;
if($zip->open($zipname))
{
for($i=0; $i<$zip->numFiles; $i++)
{ //echo 'Filename: '.$zip->getNameIndex($i).'<br />';
}
if($zip->extractTo('../StadVis/')){
sleep(1);
unlink($zipname);
}else{
return "not success";
}
$zip->close();
//chmod('../StadVis/'.$filename1, 0777);
if (rename('../'.$filename,'../versions/'.$filename))
{
return "success";
//echo "File Copy";
}
else {
return "not success";
//echo "File Not Copy";
}
}
else
{
return 'Error reading zip-archive!';
}
}
1/ Use absolute path in your script :
$path=getcwd()."/..";
2 / you work in ../ directory so change directory :
chdir('../');
3/ Combine solution 1 + 2