簡體   English   中英

filemtime()和filesize()php錯誤

[英]filemtime() and filesize() php error

我正在嘗試讀取某個目錄的所有內容。 我有下面的功能,它遍歷目錄並安排所有內容。 唯一的問題是,對於每個文件和目錄,我一直在獲取filemtime(): stat failedfilesize(): stat failed 我曾嘗試查找解決方案,但發現的任何方法均無效。 我以為這可能是權限問題,但是我可以從正在排列的目錄中進行讀寫,所以這不是問題。 有誰知道我該如何解決?

    public function arrangeContents()
    {
        $currDir = opendir($this->path);

        while($entryName = readdir($currDir))
        {
          $this->content[] = $entryName;
        }
        closedir($currDir);

        $this->content_count = count($this->content);

        for($i = 0; $i < $this->getContentCount(); $i++)
        {
            $this->names[] = $this->content[$i];
            $this->name_hrefs[] = $this->content[$i];

            $this->extns[] = $this->findExts($this->content[$i]); 

            $this->file_sizes[] = number_format(filesize($this->content[$i]));

            $this->mod_times[] = date("M j Y g:i A", filemtime($this->content[$i]));
            $this->time_keys[] = date("YmdHis", filemtime($this->content[$i]));

            $this->sortContents($this->content[$i]);
        }
    }

您輸入的文件路徑錯誤,或者您無權統計相關文件。

  1. 對於路徑,請嘗試使用DIR常量或$ _SERVER ['DOCUMENT_ROOT']確定完整路徑

  2. 為了獲得許可,PHP必須由用戶可讀該文件。 嘗試使用777測試文件的文件夾只是為了證明權限是問題。

我解決了這個問題,因為我沒有在文件前添加路徑。

如果我只是放$this->dir . '/' . $this->content[i] $this->dir . '/' . $this->content[i] 每個函數中的$this->dir . '/' . $this->content[i]都正確地給了我一切。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM