脚本宝典收集整理的这篇文章主要介绍了php – RecursiveDirectoryIterator对“打开的文件过多”抛出UnexpectedValueException,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$zip = new ZipArchive(); if ($zip->oPEn('./archive.zip',ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } $ITerator = new RecursiveiteratorIterator(new Recursivedirectoryiterator("./folder/")); foreach ($iterator as $key => $value) { try { $zip->adDFile(realpath($key),$key); echo "'$key' successfully added.\n"; } catch (Exception $e) { echo "ERROR: Could not add the file '$key': $e\n"; } } $zip->close();
Uncaught exception 'unexpectedvalueexception' with message 'RecursiveDirectoryIterator::__construct(./some/path/): Failed to open dir: Too many open files' in /some/other/path/zip.PHP:24 Stack trace: #0 [internal function]: RecursiveDirectoryIterator->__construct('./some/path/') #1 /some/other/path/zip.PHP(24): RecursiveDirectoryIterator->getChildren() #2 {main} thrown in /some/other/path/zip.PHP on line 24
iterator_to_array
函数的数组,您似乎可以根据需要迭代任意数量的文件:
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("./folder/")); $files = iterator_to_array($iterator,true); // iterate over the directory // add each file found to the archive foreach ($files as $key => $value) { try { $zip->addFile(realpath($key),$key); echo "'$key' successfully added.\n"; } catch (Exception $e) { echo "ERROR: Could not add the file '$key': $e\n"; } }
以上是脚本宝典为你收集整理的php – RecursiveDirectoryIterator对“打开的文件过多”抛出UnexpectedValueException全部内容,希望文章能够帮你解决php – RecursiveDirectoryIterator对“打开的文件过多”抛出UnexpectedValueException所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。