我使用下面的代码显示目录中的所有jpg。
$dirname = "var/www/media/";
$images = glob($dirname."*.jpg");
foreach($images as $image) {
echo '<img src="'.$image.'" /><br />';
}
在同一目录中,我有同名电影。例如:
ls var/www/media
Aliens.mpg
Aliens.jpg
Simsons.avi
Simsons.jpg
我需要每个jpg图像都可以点击,链接到相应的视频文件。
这样做有简单的方法吗?
答案 0 :(得分:2)
你走了!
注意
1)确保文件名相同。
2)您可以在变量$vidExts
和<?php
$files = glob("media/*.*");
$vid = NULL;
$imgExts = array("gif", "jpg", "jpeg", "png", "tiff", "tif");
$vidExts = array("mp4", "mpg", "avi", "mk4", "ogg", "3gp");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
$urlExt = pathinfo($files[$i], PATHINFO_EXTENSION);
if (in_array($urlExt, $imgExts)) {
for ($j=0; $j<count($files); $j++) {
$urlExt2 = pathinfo($files[$j], PATHINFO_EXTENSION);
if (in_array($urlExt2, $vidExts)) {
if (strcmp($urlExt, $urlExt2) == 0) {
$vid=$files[$j];
}
}
}
echo '<a href="'.$vid .'"><img src="'.$image .'" />'."<br /></a>";
}
}
中添加更多ext文件。
<?php
$x=1; // initially giving value for x=1
$files = glob("media/*.*");
$vid=NULL;
$vidf=$files; //making copy of files array
$imgExts = array("gif", "jpg", "jpeg", "png", "tiff", "tif");
$vidExts = array("mp4", "mpg", "avi", "mk4", "ogg", "3gp");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
$urlExt = pathinfo($files[$i], PATHINFO_EXTENSION);
if(in_array($urlExt,$imgExts )){
for($j=0; $j<count($files); $j++){
$urlExt2 = pathinfo($files[$j], PATHINFO_EXTENSION);
if(in_array($urlExt2,$vidExts )){
if(strcmp(pathinfo($files[$i], PATHINFO_FILENAME),pathinfo($files[$j], PATHINFO_FILENAME))==0){
$vid=$files[$j];
$x=0; // put the value of x=0 if video for that image found!
unset($vidf[array_search($vid , $vidf)]); // search & delete video from array with have images
}
}
}
if($x==0)
echo '<a href="'.$vid .'"><img src="'.$image .'" />'."<br /></a>";
else if($x==1){ //check if image have the video
echo 'Video for Image <b>', pathinfo($image , PATHINFO_FILENAME),'.',pathinfo($image , PATHINFO_EXTENSION), ' </b>Not Found!<br>';
$x=0;}
}
}
foreach ($vidf as $vidf) { // show let out videos who's images not found
$urlExt2 = pathinfo($vidf, PATHINFO_EXTENSION);
if(in_array($urlExt2,$vidExts )){
echo "Image of the Video <b> ",pathinfo($vidf , PATHINFO_FILENAME),'.', pathinfo($vidf , PATHINFO_EXTENSION),'</b> Not found!' ;
echo '<br>';
}
}
?>
<强>更新强>
如果找不到任何文件(例如,如果找不到视频图像,反之亦然),则会显示错误
JavaPairReceiverInputDStream<String, String> messages =
KafkaUtils.createStream(jssc, zkQuorum, groupId, topicMap);
JavaDStream<String> lines = messages.map(Tuple2::_2);
JavaDStream<String> words = lines.flatMap(x -> Arrays.asList(SPACE.split(x)).iterator());
JavaPairDStream<String, Integer> wordCounts = words.mapToPair(s -> new Tuple2<>(s, 1))
.reduceByKey((i1, i2) -> i1 + i2);