[英]Deleting “.part” files from folder with PHP
我正在使用以下命令從指定目錄中刪除所有文件。
$files = glob('path/to/temp/*');
foreach($files as $file){
if(is_file($file))
unlink($file);
}
除了部分上傳的文件,它會刪除所有內容,例如: myfile.mp3.part
我嘗試在文件路徑中指定.part只是為了看看是否可以強制這樣做:
$files = glob('path/to/temp/*.part');
但這也不起作用。 我在這里想念什么嗎? 有沒有其他方法可以刪除非活動的部分文件?
$files = scandir('/path/to/temp');
foreach($files as $key => $file) {
if ( preg_match('/.*?\.part$/', $file) ) {
unlink($file);
}
}
我正在使用類似的方法刪除文件夾中的所有文件。
$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.