包括在幻灯片中加载网页

时间:2017-05-31 14:59:47

标签: php slideshow

我是stackoverflow的新手。我正在尝试调整一个包含照片和视频的文件夹加载并显示为幻灯片显示的删除脚本。

我想添加加载网页的选项。有没有简单的方法呢?

非常感谢你。 这是我的代码:

<?php

include "class.getFiles.php";

$images = new getFiles();
// list of all files in the images folder (includes videos)
$imageArray = $images->getImageArray();

$sortedImages = new sortFiles();
$sortedImages->sortImageArray($imageArray);

// remove files not in the correct time period
$imageArray = $sortedImages->getImageArray();
$randImage = $sortedImages->randomImageNum();

$fileName = $imageArray[$randImage];

$info = new SplFileInfo($fileName);



?>
 <!DOCTYPE html>
<html>
<head>
<title>Fiction Slideshow</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
<?php 

if($info->getExtension() == "mp4")
{
    echo '<video id="vid" class="videoDisplay" autoplay>
  <source src="images/'.$fileName.'" type="video/mp4">
  Your browser does not support the video tag.
</video>';

   echo '<script type="text/javascript">
    var vid = document.getElementById("vid");
    vid.addEventListener("ended", function(){
        window.location.reload();
    });
   </script>';

}
else
{
    echo '<img class="imageDisplay" src="images/'.$fileName.'" />';
    echo '<script type="text/javascript">
    setTimeout(function(){
        window.location.reload();
    }, 30000);
   </script>';

}
 ?>
</body>

</html> 

这是另一个脚本调用的class.getFiles.php文件。

<?php

class getFiles {

protected $dir;
protected $imageArray;


function __construct()
{
    $this->get_dir();
    $this->get_images();
}

protected function get_dir()
{
    $this->dir = getcwd();
}

protected function get_images()
{

    if(count(scandir($this->dir."/images")) != 2)
    {
        $this->imageArray = scandir($this->dir."/images");
    }
    else
    {
        die("There are no files in the directory");
    }

}



public function getImageArray()
{
    return $this->imageArray;
}

}

class sortFiles {

protected $sortedImageArray = [];


public function sortImageArray($imageArray)
{
    foreach ($imageArray as $imageFile ) 
    {  
        if($imageFile !== ".." && $imageFile !== ".")
        {

        $imagePath = $imageFile;
        $imageFile = (substr($imageFile, 0, -4));
        $BeginningPos = strpos($imageFile, '_');
        $beginningDate = (substr($imageFile, 0, $BeginningPos));

        $beginningDateformatted = str_replace("-","/", $beginningDate);

        $stringToStartTime = strtotime($beginningDateformatted);


        $EndingPos = strpos($imageFile, '_', $BeginningPos  + strlen('_'));
        $EndingPos = $EndingPos + 1;
        $EndingDate = (substr($imageFile, $EndingPos));
        $EndingDateformatted = str_replace("-","/", $EndingDate);
        $stringToEndTime = strtotime($EndingDateformatted);

        $time = time();

        if($time <= $stringToStartTime && $time >= $stringToEndTime)
            {
                array_push($this->sortedImageArray, $imagePath);

            }

        }

    }

}

public function getImageArray()
{
    if(count($this->sortedImageArray) != 0)
    {
        return $this->sortedImageArray;
    }
    else
    {
        die("There are no files in the time range");
    }
}

public function randomImageNum()
{
    $imageArrayLength = count($this->sortedImageArray);
    $imageRand = rand(0, $imageArrayLength-1);
    return $imageRand;
}

}

&GT;

1 个答案:

答案 0 :(得分:0)

您可以将网页保存为媒体文件夹中的链接。例如,如果要显示网页http://www.example.com,则可以在媒体文件夹中创建文件webpage1.txt。此文件可以包含http://www.example.com链接。

在您的代码中,您可以添加一个新条件来检查文件类型是否为txt。如果文件类型是txt,那么您的代码可以读取文件中的链接并使用iframe显示链接。以下代码应该有效:

else if(strpos($fileName, "weblink") !== false)
{
   /** The path to the web page link */
   $file_path     = (getcwd() . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . $fileName);
   /** Read contents of file */
   $web_page_link = file_get_contents($file_path);
   /** Display the link in iframe */
   echo "<iframe src='".$web_page_link."' width='100%' height='100%'></iframe>";
}

上面的代码应该高于else语句