PHP 和 SWF - 幻灯片放映不显示



我正在尝试显示幻灯片。slide_auto.php与我的slideS_img文件夹位于同一目录中

这是我slide_auto.php文件:

<?php
$file_dir="slideS_img"; //change this to a folder name
$show_titles=false; //change to false if you don't want to see the captions
$omit_chars=0; //how many characters to cut off the title's front
$link_to_image=false; //do you want to display links?
print '<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow  displayTime="5" 
            transitionSpeed=".7"
            ...more code...
            >';
            $dir=opendir($file_dir);
        $xml_string= array();
            while ($file=readdir($dir))
            {
                if(substr($file, -3) == "jpg" || substr($file, -4) == "jpeg" ){
                $tmp_str = '<image img="'.$file_dir.'/'.$file.'" ';
                if($show_titles){
                    $file_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars);
                    $tmp_str .= 'caption="'.$file_title.'" ';
                }
                if($link_to_image){
                    $link_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars);
                    $tmp_str .= 'link="'.$file_dir.'/'.$file.'" target="_blank"';
                }
                    $tmp_str .=" />";
                    array_push($xml_string, $tmp_str);
                }

            }
            sort($xml_string);
            for($i=0; $i<count($xml_string); $i++){
            print $xml_string[$i];
            }
closedir($dir);
print '</slideshow>';
?>

AMD 我的幻灯片页面.php:

<?php
require_once('slideshow/slide_auto.php')
?>
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div align="center">
<br />
<br />
<br />
<div id="flashcontent">
  This text is replaced by the Flash movie.
</div>
<script type="text/javascript">
   swfobject.embedSWF("slideshow.swf?file=slideshow/slide_auto.php", "gallery", "100%", "100%", "7", "#333333");
   so.write("flashcontent");
</script>
</div>
</body>
</html>

我收到一个错误,说警告:opendir(slideS_img) [function.opendir]:无法打开目录:第 62 行的/[path]/slideshow/slide_auto.php 中没有这样的文件或目录

有什么帮助吗?谢谢<</p>

div class="one_answers">

包含的文件假定您从中包含它们的文件的工作目录。您的父幻灯片页面脚本在(例如)中

 /home/sites/example.com/html

它将成为幻灯片脚本的工作目录。所以opendir实际上是作为

 /home/sites/example.com/html/slideS_img

而不是

 /home/sites/example.com/html/slideshow/slideS_image

您必须修改 opendir 调用才能使用更具体的目录。

Marc 的解决方案实际上是正确的。如果我能尝试详细说明一下,当你包括slide_auto.php时,你可以想到以下情况:

  1. PHP 插入文件slide_auto.php中的文本,其中可以找到 include 命令。
  2. 因此,当$file_dir="slideS_img";出现时,它会尝试在slideshowpage.php下找到目录,而不是slide_auto.php

此操作失败,因为实际图像文件夹位于目录幻灯片中

如果直接调用slide_auto.php(或在 Flash 应用程序中),则其目录是幻灯片,并且您应该能够获取 XML,而不会出现任何进一步的错误。

最新更新