PHP filesize()可用于除一个文件之外的所有文件,并提供stat失败错误 [英] PHP filesize() works on all but one file, gives stat failed error

查看:164
本文介绍了PHP filesize()可用于除一个文件之外的所有文件,并提供stat失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个PHP页面,该页面通过抓取现有的HTML页面来生成播客feed.一切正常,但是我的mp3文件之一给出了"filesize():状态失败"错误.据我所知,该文件没有损坏,并且可以正常播放.我还将文件重新上传到服务器.它在所有文件大小的中间范围内,因此我认为文件不会太大.因为每个其他文件都返回文件大小,所以我假设问题出在mp3文件上,而不是服务器配置上.还有什么我应该检查的吗?

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..)

文件名是"12-20-09_AM_Podcast.mp3",该文件遵循其他每个文件的命名约定,并且所有文件都具有644的权限.完整的错误代码是

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 />

推荐答案

出于某些原因,domain.org上的Web服务器未返回Content-Length标头字段,这导致

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

如果文件存储在本地,请改为 filesize() 文件的本地副本.如果不是,您将无法解决此问题,因为这是domain.org的Web服务器上的问题.您可以通过在本地下载文件并检查 filesize() 来解决此问题,但这会降低您的速度主要页面.

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.

如果文件存储在本地,请再次检查文件名或锚点.您可能拼错了一个(或两者都拼写错误),而Apache mod_speling正在为您修复它.

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.

这篇关于PHP filesize()可用于除一个文件之外的所有文件,并提供stat失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆