如何使 PHP 从幻灯片播放变为带分页的视频播放器
我对创建动态页面完全陌生 - 所以目前,我使用 txt 文件来管理我的简单数据!我先解释一下我的设置。我有一个 php 页面 - 它从两个 .txt 文件获取数据:
brief.txt: written content (title and supporting text)
photos.txt: image file names.
我正在使用 php 分页,这通过引用我在 .txt 文件中使用的数字来更改 php 页面中的内容,这是我的代码使用:
<?php
$data=file("brief.txt");
$pages=0;
foreach($data as $temp){
$x=explode("|",$temp);
if($x[0]>0){
$pages=$pages+1;
}
}
if($_GET['p']){
$page=$_GET['p'];
}
if($_GET['i']){
$index=$_GET['i'];
}
if($index == "p"){
$page=$page-1;
}
if($index == "n"){
$page=$page+1;
}
if($page < 1){
$page=1;
}
if($page > $pages){
$page=$pages;
}
$line=$data[$page-1];
$fields=explode("|",$line);
?>
这是我的文本文件的示例
brief.txt:
1|TITLE 1|Content goes here
2|TITLE 2|Content goes here
photos.txt:
1|imageone1.jpg
2|imagetwo1.jpg
希望一切都有意义!现在,我的问题是,我有一些视频文件。目前,图像以 jquery 幻灯片形式加载。我想以某种方式更改脚本,例如,当它使用视频文件创建第 3 页时,它不会创建幻灯片,而是创建一个视频播放器并可以加载放置在 txt 中的视频的 url文件。我目前用于 jquery 幻灯片的代码是这样的:
<?php
echo"
<div id='portfolioslider'><div class='slider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<div><img src='images/work/$photo' alt='' /></div>\n";
}
}
echo"</div></div>"?>
当您转到带有视频的页面时,我希望上面的代码进行类似的更改:
<iframe src="http://player.vimeo.com/video/23024550?title=0&byline=0&portrait=0" width="1024" height="576" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
如果您返回或前进到一个没有视频的页面没有视频,我希望它改回原来的 jquery 幻灯片...
请有人帮我提供完成这项工作所需的必要代码!我是一个非常初级的编码员:(
I'm completely new to creating dynamic pages - so for the moment, I am using txt files to manage my simple data! I'll explain my set up first. I have one php page - it gets data from two .txt files:
brief.txt: written content (title and supporting text)
photos.txt: image file names.
I am using php pagination, and this changes the content in the php page by referring to the numbers I have used in the .txt file, here is the code I am using:
<?php
$data=file("brief.txt");
$pages=0;
foreach($data as $temp){
$x=explode("|",$temp);
if($x[0]>0){
$pages=$pages+1;
}
}
if($_GET['p']){
$page=$_GET['p'];
}
if($_GET['i']){
$index=$_GET['i'];
}
if($index == "p"){
$page=$page-1;
}
if($index == "n"){
$page=$page+1;
}
if($page < 1){
$page=1;
}
if($page > $pages){
$page=$pages;
}
$line=$data[$page-1];
$fields=explode("|",$line);
?>
and this is an example of my text file
brief.txt:
1|TITLE 1|Content goes here
2|TITLE 2|Content goes here
photos.txt:
1|imageone1.jpg
2|imagetwo1.jpg
Hopefully that all makes sense! Now, my problem is, I have a few video files. At the moment, the images load in a jquery slideshow. I would like to somehow have the script change, for example, when it makes page 3 with a video file it doesn't create the slideshow, but instead creates a video player and can load the url of my video that is placed in the txt file. The code I am using at the moment for the jquery slideshow is this:
<?php
echo"
<div id='portfolioslider'><div class='slider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<div><img src='images/work/$photo' alt='' /></div>\n";
}
}
echo"</div></div>"?>
I would like the above code, to change similar to this when you go to a page with a video:
<iframe src="http://player.vimeo.com/video/23024550?title=0&byline=0&portrait=0" width="1024" height="576" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
And if you go back or forward to a page which doesn't have a video, I would like it to change back to the original jquery slideshow...
Please can someone help me out with the necessary code I would need to make this work! I am very much a beginner coder :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:假设我理解你的逻辑结构,并且我可能错过了一些东西:
也许,使用videos.txt来存储视频,而不是将两者都放在photos.txt中?另外,考虑使用 MySQL 数据库来实现此目的。
如果您绝对必须使用这种编码方式,我将创建一个接受文件名的函数,并根据扩展名确定它是视频还是图像,从而决定要加载的内容以及如何加载。
或者,您可以向 photos.txt 文件添加一个额外的标志:
其中第三个“1”表示视频,“0”表示照片?这是您的元数据,因此您可以决定其结构。
Edit: Assuming I understand your logic's structure, and it's possible I missed something:
Perhaps, using a videos.txt to store videos, as opposed to putting both inside of photos.txt? Also, look into using a MySQL database for this.
And if you absolutely must use this manner of coding, I'd create a function that accepts a file name, and depending on the extension determines if it is a video or an image, thus dictating what content to load, and how.
Or, you can add an extra flag to your photos.txt file:
Where the third '1' means video, and a '0' means photo? It's your metadata, so you can dictate its structure.
基本上,您需要做的只是检查当前文件是图片还是视频。最简单的方法是查看扩展名。您的视频也存储在 photos.txt 中,对吗?尝试这样的事情:
Basically what you need to do is just check to see if the current file is a picture or a video. The easiest way would be to look at the extension. Your videos are also stored in photos.txt, right? try something like this: