使用php unlink函数删除临时文件时,权限被拒绝错误

时间:2013-12-16 06:23:27

标签: php

foreach (new DirectoryIterator($tempFilesPath) as $fileData) 
{ 
   $fileName            = $fileData->getFileName();
   $fullFilePath        = $tempFilesPath.$fileName;
   $fileExtension       =  $fileData->getExtension();
  { 
    switch($fileExtension)
     case 'csv':unlink($fullFilePath); break;
     case 'pdf' :unlink($fullFilePath); break;
     case 'html': unlink($fullFilePath); break;
 }
}
 /* Delete the files from temp directory , Permission denied error is coming */

1 个答案:

答案 0 :(得分:0)

是webserver temp还是系统temp?

尝试使用chown()设置文件权限 CHOWN($ fullFilePath,465); //插入无效的UserId以设置为Nobody Owner;例如465 //然后尝试取消链接文件

如果它不起作用尝试 chmod($ fullFilePath,0666)

Refer here