【发布时间】:2017-11-10 10:36:58
【问题描述】:
我想创建删除列表,但 mp3 和 mp4 文件除外
我的代码是
错误 致命错误:在第 39 行的 E:\xampp\htdocs\tes\index.php 中调用未定义函数 endsWith()
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
$zip->close();
// Add current file to "delete list"
// delete it later cause ZipArchive create archive only after calling close function and ZipArchive lock files until archive created)
if ($file->getFilename().endsWith(".mp3")) error at this code
{
$filesToDelete[] = $filePath;
}
}
}
请大家帮帮我
【问题讨论】:
-
检查文件的mime类型,文件扩展名(例如.mp3)不可靠
-
它无法解决
-
我注意到你已经指定了
php-5.3标签。请注意,这个 php 版本现在非常旧且不受支持。您应该紧急考虑升级到至少 5.6 版以避免安全问题。