note 123327 added to ziparchive.addfile
| From: | raja at rsdisk dot com | Date: | Sat, 10 Nov 2018 08:57:59 +0000 |
| Subject: | note 123327 added to ziparchive.addfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209659@lists.php.net to get a copy of this message | ||
zip->addfile function does not add file to archive immediately. It is cued and executed at
zip->close()
I had backup files in a dir. with a foreach statement I was adding the file to an archive and then
moving the files into dump dir immediately.
This caused an error.
<?php
$dir = getcwd().'/';
$dirContent = scandir('./');
foreach($dirContent as $file)
if(strpos($file, '.sql')!==false)
{
echo "adding $file ......";
$zip->addFile($file);
$newFileName = $dir."done/$file";
rename($dir.$file, $newFileName);
echo( "; file added\n");
}
$zip->close();
?>
The $zip->close() needs to execute before moving files,
<?php
foreach($dirContent as $file)
if(strpos($file, '.sql')!==false)
{
echo "adding $file ......";
$zip->addFile($file);
echo( "; file added\n");
}
$zip->close();
foreach($dirContent as $file)
if(strpos($file, '.sql')!==false)
{
$newFileName = $dir."done/$file";
rename($dir.$file, $newFileName);
echo( "$file moved\n");
}
?>
----
Server IP: 208.43.231.9
Probable Submitter: 14.194.236.203
----
Manual Page -- http://php.net/manual/en/ziparchive.addfile.php
Edit -- https://master.php.net/note/edit/123327
Del: integrated -- https://master.php.net/note/delete/123327/integrated
Del: useless -- https://master.php.net/note/delete/123327/useless
Del: bad code -- https://master.php.net/note/delete/123327/bad+code
Del: spam -- https://master.php.net/note/delete/123327/spam
Del: non-english -- https://master.php.net/note/delete/123327/non-english
Del: in docs -- https://master.php.net/note/delete/123327/in+docs
Del: other reasons-- https://master.php.net/note/delete/123327
Reject -- https://master.php.net/note/reject/123327
Search -- https://master.php.net/manage/user-notes.php