2017-05-31 67 views
0

我是全新的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 

类的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; 
} 

}

类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; 
} 

}

?>

回答

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语句上述

+0

非常感谢你Nadir。我会尝试一下,如果它有效,我会告诉你。再次谢谢你!! – JD10081986

+0

它没有工作。我认为这是导致问题的“class.getFiles.php”。我将把代码放到我原来的问题中。你能帮我解释为什么它不起作用吗?感谢您的时间。 – JD10081986

+0

尝试将网页文件放入名为“网页”的文件夹中。再次尝试上面的代码。我已经更新了它。它应该高于您发布的第一个示例文件中的最后一个else语句。 –

0

看起来这是在这一刻是不可能的任务。关闭此...