[英]How to output image, video and audio players in a new window
我有三个表行,其中包含各自行中的图像,视频和音频列表:
echo '<td width="11%" class="imagetd">'. ( ( empty ($arrImageFile[$key]) ) ? " " : '<ul class="qandaul"><li>'.htmlspecialchars( is_array( $arrImageFile[$key] ) ? implode(",", $arrImageFile[$key]) : $arrImageFile[$key] ) ). '</li></ul></td>' . PHP_EOL;
echo '<td width="11%" class="videotd">'. ( ( empty ($arrVideoFile[$key]) ) ? " " : '<ul class="qandaul"><li>'.htmlspecialchars( is_array( $arrVideoFile[$key] ) ? implode(",", $arrVideoFile[$key]) : $arrVideoFile[$key] ) ). '</li></ul></td>' . PHP_EOL;
echo '<td width="11%" class="audiotd">'. ( ( empty ($arrAudioFile[$key]) ) ? " " : '<ul class="qandaul"><li>'.htmlspecialchars( is_array( $arrAudioFile[$key] ) ? implode(",", $arrAudioFile[$key]) : $arrAudioFile[$key] ) ). '</li></ul></td>' . PHP_EOL;
该列表是一个包含来自数据库的数据的数组。 下面是视频数组和数据库的代码。 音频和图像具有类似的设置
$vidquery = "SELECT s.SessionId, q.QuestionId, v.VideoId, VideoFile
FROM Session s
INNER JOIN Question q ON s.SessionId = q.SessionId
INNER JOIN Video_Question vq ON q.QuestionId = vq.QuestionId
INNER JOIN Video v ON vq.VideoId = v.VideoId
WHERE s.SessionId = ?";
global $mysqli;
$vidqrystmt=$mysqli->prepare($vidquery);
// You only need to call bind_param once
$vidqrystmt->bind_param("i",$_POST["session"]);
// get result and assign variables (prefix with db)
$vidqrystmt->execute();
$vidqrystmt->bind_result($vidSessionId,$vidQuestionId,$vidVideoId,$vidVideoFile);
$arrVideoFile = array();
while ($vidqrystmt->fetch()) {
$arrVideoFile[] = basename($vidVideoFile);
}
$vidqrystmt->close();
现在,它只是在项目符号列表中列出图像,视频和音频文件名。 但我想要做的是我想将每个文件设置为超链接,这样如果用户点击任一链接,它将在单独的页面中显示图像,视频或音频(将打开一个单独的窗口) ,作为较大的或显示播放视频或音频的播放器。
我的问题是如何做到这一点,我需要做以下哪些步骤?
我的建议是将每个媒体元素(音频,图像,视频)包装成标签 - 锚(a),例如:
<a href='previewImage.php?imgId=[xxx]' target='_blank'>myImage.jpg</a>
其中[xxx]是图像的id或其名称。
在previewImage.php
您可以使用$_GET['imgId']
获取它,从DB中选择并显示它。 类似于previewVideo.php
和previewAudio.php
<?php
//start:procedure
$img_result = '';
if(empty($arrImageFile[$key])){
$img_result = ' ';
}else{
$img_$result .= '<ul class="qandaul"><li>';
if(is_array( $arrImageFile[$key] )){
foreach($arrImageFile[$key] as $filename){
$img_$result.= CreateLink($filename, "image");
}
}else{
$img_$result.= CreateLink($arrImageFile[$key], "image");
}
$img_result.= '</li></ul>';
}
//end:procedure
echo '<td width="11%" class="imagetd">'.$img_result.'</td>' . PHP_EOL;
function CreateLink($filename, $type){
if($type == 'image'){
return '<a href="imageviewer.php?filename='.$filename.'" title="Click to view in New window" target="_blank">'.htmlspecialchars($filename).'</a>';
}
if($type == 'video'){
}
if($type == 'audio'){
}
}
?>
您还可以使用结构化方法为所有这些函数创建一个通用函数(从上面的启动过程到结束)
<?php
echo '<td width="11%" class="imagetd">'.customfunction($arrImageFile[$key]).'</td>' . PHP_EOL;
//same idea for other td also
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.