2015-07-12 38 views
0

我想簡單地清空目錄中的所有文件,但是我一直收到file_put_contents中的路徑是目錄的錯誤。目錄中的空文件

 //empty the cache 
     $files = scandir('tmp/whazzup/cache/'); 
     if($files!=false){ 
      foreach($files as $file){ 
       file_put_contents('tmp/whazzup/cache/'.$file, ''); 
      } 
     } 

回答

1

PHP scandir返回所有文件和目錄的數組。所以你得到一個數組,如...和其他子目錄。

你應該做你的foreach循環什麼:

foreach ($files as $file) { 
    // ignore directories 
    if (is_dir($file)) { 
     continue; 
    } 

    // process files 
    file_put_contents(...); 
} 
相關問題