简体   繁体   English

使用PHP从文件夹中删除“ .part”文件

[英]Deleting “.part” files from folder with PHP

I'm using the following to delete all files from the specified directory. 我正在使用以下命令从指定目录中删除所有文件。

$files = glob('path/to/temp/*');
foreach($files as $file){
if(is_file($file)) 
unlink($file);
}

It removes everything other than partially uploaded files eg : myfile.mp3.part 除了部分上传的文件,它会删除所有内容,例如: myfile.mp3.part

I've tried specifying .part in the file path just to see if I can force it that way : 我尝试在文件路径中指定.part只是为了看看是否可以强制这样做:

$files = glob('path/to/temp/*.part');

But that doesn't work either. 但这也不起作用。 Am I missing something here? 我在这里想念什么吗? Is there a different method for deleting non-active partial files? 有没有其他方法可以删除非活动的部分文件?

$files = scandir('/path/to/temp');

foreach($files as $key => $file) {
    if ( preg_match('/.*?\.part$/', $file) ) {
        unlink($file);
    }
}

I'm using something likes this to delete all files in a folder. 我正在使用类似的方法删除文件夹中的所有文件。

$dir = "/path/to/temp";
$files = scandir($dir);
foreach($files as $file){
    $path = $dir."/".$file;
    if(is_file($path)) unlink($path);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM