2013-12-16 13 views
0
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 */ 
+0

請添加導致權限錯誤的代碼。你是否也在管理服務器?可能是'unlink'不是允許的功能,或者你試圖從一個目錄中取消鏈接的目錄,你不允許從 – nrathaus

+0

訪問文件的權限,你想從其他域使用同一個用戶嗎? 你的php是什麼? cli或cgi其重要;) –

回答

0

它是Web服務器的臨時文件還是系統臨時文件?

嘗試使用chown設置文件的權限() chown($ fullFilePath,465); //插入一個無效的UserId設置爲Nobody Owner;例如465 //然後嘗試unlink'ing文件

如果亙古不變的工作嘗試做 搭配chmod($ fullFilePath,0666)

Refer here

+0

chmod($ fullFilePath,0666)它會在linux上工作嗎? – user3098202

+0

它工作得很好.. – user3098202