开发者

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

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; /开发者_Python百科/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 />


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜