【问题标题】:read a file created with fopen php function读取使用 fopen php 函数创建的文件
【发布时间】:2014-10-06 15:28:07
【问题描述】:

我在读取使用 fopen 函数创建的文件时遇到问题,文件存在于服务器上但无法访问,我不知道为什么,如果我通过 ftp 下载它存在,但我无法访问它来自 php,这是创建文件的代码:

if (!(file_exists("./media/mod_xml/ $rssname "))) {
$myfile = fopen("./media/mod_xml/ $rssname ", "w+b") or die("Unable to open file!");
$txt = '<rss version="2.0" xmlns:jwplayer="http://rss.jwpcdn.com/">
';
$txt .='<channel>
';
foreach ($xml->video as $video) {
    $txt .='<item>
    ';
    $txt .='<title>'.$xml->video->titolo.'</title>
    ';
    $txt .='<description>'.$xml->video->descrizione.'</description>
    ';
    $txt .='<jwplayer:image>'.$xml->video->preview.'</jwplayer:image>
    ';
    $txt .='<jwplayer:source file="'.$xml->video->video.'" />
    ';
    $txt .='</item>
    ';
}
$txt .='</channel>
';
$txt .='</rss>
';
fwrite($myfile, $txt);
fclose($myfile);
}

这是试图读取文件的代码:

<script type="text/javascript">
    jwplayer("jwplayer<?php echo $xml->video->id;?>").setup({
        playlist: "http://www.example.com/media/mod_xml/<?php echo $xml->video->id;?>.rss",
        width: <?php echo $params->get('vwidth', ''); ?>,
        height: <?php echo $params->get('vheight', ''); ?>
    });
</script>

其中“mysite.com”是 rss 文件所在站点的 URL。如果我打开 media/mod_xml/ 文件夹,文件在那里,并且格式正确,但由于某些奇怪的原因 php 不读取它们。

如果我尝试将浏览器指向文件,我会收到 404 Not Found 错误,告诉我

在此服务器上找不到请求的 URL /media/mod_xml/399.rss。

但是文件在那里,有人可以帮忙吗? tnk 提前 :)

编辑:

我在另一个服务器/域上加载一个 php 文件并将其“转换”为标准 rss 以将其传递给 jwplayer,文件被很好地读取并“转换”得很好:

$xmlurl = $params->get('xmlurl', '');
$xml = simplexml_load_file($xmlurl);
$rssname = $xml->video->id;
$rssname .=".rss";

【问题讨论】:

  • 您在mod_xml/ $rssname 中有一个空间,这可能是个问题。也可能是路径问题。
  • 不,因为文件存在并写在“media/mod_xml”文件夹中,我看到它们,我下载它们,如果我在 Dreamweaver 中打开它们是格式正确的 rss :)
  • 你使用的if (!(file_exists不应该是if(file_exists吗?你告诉 PHP “如果文件 not 存在,打开同一个文件”。试试if(file_exists("./media/mod_xml/ $rssname "))
  • 我告诉 php 只有在文件不存在的情况下才做某事,但这不是问题,文件存在,如果我删除它们,它们将被重新创建,并且位于“media/ mod_xml”文件夹,文件在那里并且运行良好。我使用 fopn 创建文件不打开它,fopen 也可以用于创建文件w3schools.com/php/php_file_create.asp
  • 可以粘贴文件的权限吗?只是为了确保您(阅读:您的网页)可以访问磁盘上的文件。

标签: php joomla rss joomla2.5 jwplayer6


【解决方案1】:

我解决了这个问题。问题是文件已创建,但它们似乎不是正确的 RSS 文件,

我编辑了代码,并使用此代码命名文件和上传文件夹:

$xmlurl = $params->get('xmlurl', '');
$xml = simplexml_load_file($xmlurl);
$rssname = $xml->video->id;
$rssname .=".rss";
$upload_dir = "./media/mod_xml/";
if (!(file_exists($upload_dir.$rssname))) {
$myfile = fopen($upload_dir.$rssname, "w") or die("Unable to open file!");
...}

现在文件被创建为适当的 RSS 文件,jwPlayer 就像一个魅力,反正 tnks...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-06
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 2015-10-26
    相关资源
    最近更新 更多