PHP filesize() works on all but one file, gives stat failed error

安稳与你 提交于 2020-01-02 03:16:17

问题


I'm writing a PHP page that generates a podcast feed by scraping an existing HTML page. Everything works great, but one of my mp3 files gives a "filesize(): stat failed" error. As best as I can tell, the file isn't corrupted, and it plays perfectly fine. I've also reuploaded the file to the server. It falls in the middle range of all the file sizes, so I don't think the file is too large. Because every other file returns a file size, I'm assuming the problem is with the mp3 file, not with my server configuration. Is there something else I should be checking?

Here's the relevant part of my code:

$i = 1; //skipping header row on table
do {
    $tr = $table->find('tr', $i);

    $date = $tr->find('div', 0)->plaintext;
    $datetime = new DateTime($date);
    $speaker = $tr->find('div', 1)->plaintext;
    $title = $tr->find('div', 2)->plaintext;
    $url = $tr->find('div', 3)->find('a', 0)->href;
    $fullurl = "http://domain.org/resources/".$url;
    $filesize = filesize($url); //<---works on every file except one

    echo "<item><title>".$title."</title>\n";
    echo "<description>".$title." - ".$datetime->format('D, M jS, Y')." - ".$speaker."</description>\n";
    echo "<itunes:author>".$speaker."</itunes:author>\n";
    echo "<enclosure url=\"".$fullurl."\" length=\"".$filesize."\" type=\"audio/mpeg\"/>\n";
    echo "<guid isPermaLink=\"true\">".$fullurl."</guid>\n";
    echo "<pubDate>".$datetime->format('r')."</pubDate>\n";
    echo "<itunes:explicit>clean</itunes:explicit></item>\n\n";

    $i++;
}while ($table->find('tr', $i) != NULL);

As requested: (do people point out edits? This is my first question here..)

The filename is "12-20-09_AM_Podcast.mp3" which follows the naming convention of every other file, and all the files have permissions of 644. The full error code is

<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for audio/12-20-09_AM_Podcast.mp3 in <b>/homepages/1/d106955786/htdocs/victory/resources/podcast1.php</b> on line <b>45</b><br />

回答1:


For some reason the web-server on domain.org isn't returning a Content-Length header field, which is causing filesize() to fail.

If the file is stored locally, filesize() the local copy of the file instead. If not, you cannot fix this issue as it is a problem on domain.org's web-server. You could work around the issue by downloading the file locally and checking filesize() then, but this will slow down your page majorly.

If the file is stored locally, check your file name or your anchor again. You might have misspelled one (or both) and Apache mod_speling is fixing it for you.



来源:https://stackoverflow.com/questions/2203679/php-filesize-works-on-all-but-one-file-gives-stat-failed-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!