I am failing badly when it comes to using iframes and I need some help. I have never used an iframe before, this is my first time.
Here is a doucment on what I am trying to follow to produce an iframe with the galleria slider: http://galleria.io/docs/references/data/
What I have is a jwplayer and I want to access a video(s) using an iframe to retrieve the videos which are in the video.php page. If there is a single video, then simply retrieve the correct video from the video.php page but if there are multiple videos, then retrieve the correct multiple videos and display them in the galleria slider. But my question is how can I get the iframe to work in order to do this?
Below is the video.php page where it displays the jwplayer:
<div id="myElement-<?php echo $key.'-'.$i; ?>">Loading the player...
<script type="text/javascript">
jwplayer("myElement-<?php echo $key.'-'.$i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>",
width: 480,
height: 270
});
<?php $i++; ?>
Below is the code where it checks if the video is a single or multiple, displays the galleria slider if multiple and this is where the iframe is placed:
if(count($arrVideoFile[$key]) == 1){
foreach ($arrVideoFile[$key] as $v) { ?>
var data = [
{
iframe: 'video.php'
}
];
<?php
}
}else if(count($arrVideoFile[$key]) > 1){
?>
<style>
#galleriavideo_<?php echo $key; ?>{ width: 500px; height: 300px; background: #000 }
</style>
<div id="galleriavideo_<?php echo $key; ?>">
<?php
foreach ($arrVideoFile[$key] as $v) { ?>
<script type="text/javascript">
var data = [
{
iframe: 'video.php'
}
];
</script>
</div>
<?php } ?>
</div>
<script type="text/javascript">
Galleria.loadTheme('jquery/classic/galleria.classic.min.js');
Galleria.run('#galleriavideo_<?php echo $key; ?>');
</script>
<?php
}
}
//end:procedure video
EDIT:
video.php
<?php
$key = filter_input(INPUT_GET, "key", FILTER_SANITIZE_STRING);
$i = filter_input(INPUT_GET, "i", FILTER_SANITIZE_NUMBER_INT);
$v = filter_input(INPUT_GET, "v", FILTER_SANITIZE_STRING);
?>
<div id="myElement-<?php echo $key.'-'.$i; ?>">Loading the player...
<script type="text/javascript">
jwplayer("myElement-<?php echo $key.'-'.$i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>",
width: 480,
height: 270
});
</script>
</div>
assessment.php:
if(count($arrVideoFile[$key]) > 1){
?>
<style>
#galleriavideo_<?php echo $key; ?>{ width: 500px; height: 300px; background: #000 }
</style>
<div id="galleriavideo_<?php echo $key; ?>">
<?php
foreach ($arrVideoFile[$key] as $v) { ?>
<img class="iframe">
<?php $i++; ?>
<?php } ?>
</div>
<script type="text/javascript">
Galleria.loadTheme('jquery/classic/galleria.classic.min.js');
Galleria.run('#galleriavideo_<?php echo $key; ?>');
</script>
<?php
}
Here is a short example on how to use Galleria with jwplayer. You can try to adapt it to your code then.
First, there is the video.php file which contains the jwplayer:
<div id="container"></div>
<script type="text/javascript" src="/path/to/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("container").setup({
file: "http://content.bitsontherun.com/videos/3XnJSIm4-kNspJqnJ.mp4",
image: "http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg"
});
</script>
Then, there is the gallery.php file, which contains the slider:
<div id="galleria" style="height:350px; width:550px;">
<img class="iframe">
</div>
<script type="text/javascript" src="/path/to/jquery.js"></script>
<script type="text/javascript" src="/path/to/galleria.js"></script>
<script type="text/javascript">
Galleria.loadTheme('/path/to/galleria.classic.min.js');
Galleria.run('#galleria');
</script>
If you want to display multiple videos in the slider, you can imagine a solution where video.php takes a parameter and loads a video according to it, i.e. video.php?id=xx
Edit: to clarify a bit
Your video.phpfile should take some parameters:
$key = filter_input(INPUT_GET, "key", FILTER_SANITIZE_STRING);
$i = filter_input(INPUT_GET, "i", FILTER_SANITIZE_NUMBER_INT);
$v = filter_input(INPUT_GET, "v", FILTER_SANITIZE_STRING);
<div id="myElement-<?php echo $key.'-'.$i; ?>">Loading the player...
<script type="text/javascript" src="/path/to/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("myElement-<?php echo $key.'-'.$i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>",
width: 480,
height: 270
});
And then in the gallery.php file:
<div id="galleria" style="height:350px; width:550px;">
<img class="iframe">
<img class="iframe">
<img class="iframe">
...
</div>
Related
How do I write my php path with variables inside the embedded JWplayer Javascript?
I am new to php and have no code experience in Javascript.
I would appreciate any help.
**This absolute path works:**
<script type="text/javascript">
jwplayer("myElement").setup({
file: "/uploads/example.mp4",
height: 360,
image: "http://saradyso.com:8020/SuperContainer/RawData/MediaWeb/REG002133749/ADP100000033/Video1.mp4",
width: 640
});
</script>
**This doesn't work:**
<script type="text/javascript">
jwplayer("myElement").setup({
file: "/uploads/example.mp4",
height: 360,
image:"http://'.$Domain.':'.$Port.'/'.$ContainerV.'/'.$FileName.'/'.$SubFolder.'.mp4'",
width: 640
});
</script>
Just like that
<?php $your_path = "some/path/to/to.image" ?>
<script type="text/javascript">
jwplayer("myElement").setup({
file: "/uploads/example.mp4",
height: 360,
image: <?php ehco $your_path ?>,
width: 640
});
</script>
use echo inside php block like this.
<script type="text/javascript">
jwplayer("myElement").setup({
file: "/uploads/example.mp4",
height: 360,
image:"http://<?php echo $Domain ?>:<?php echo $Port ?>/<?php echo $ContainerV ?>/<?php echo $SubFolder ?>/<?php echo $FileName ?>.mp4",
width: 640
});
</script>
I am using a JW video player and the way it is implemented for a single video is as below
<div id="myElement">Loading the player...</div>
<script type="text/javascript">
jwplayer("myElement").setup({
file: "<?php echo $dbVideoFile; ?>"
});
</script>
</div>
No what I want to do is that I want to do is loop through each existing video and to display a jw video player for each video. Only problem is that it is not quite working, it is only display the jsplayer for one video, the other videos do not show anything but blank. What am I doing wrong below:
<p>
<?php foreach ($arrVideoFile[$key] as $v) { ?>
<div id="myElement">Loading the player...
<script type="text/javascript">
jwplayer("myElement").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>"
});
</script>
</div>
<?php } ?>
</p>
id tag should be unic so JWPlayer is confused when calling #myElement
Try incrementing a value and dynamically rename "myElement-" + i
I didn't get to test but that shoudl work:
<p>
<?php
$i = 0;
foreach ($arrVideoFile[$key] as $v) { ?>
<div id="myElement-<?php echo $i; ?>">Loading the player...
<script type="text/javascript">
jwplayer("myElement-<?php echo $i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>"
});
<?php $i++; ?>
</script>
</div>
<?php } ?>
</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script src="<?php $this->baseUrl()?>/public/js/jQuery.bubbletip-1.0.6.js" type="text/javascript"></script>
<link href="<?php $this->baseUrl()?>/public/js/bubbletip/bubbletip.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
for(i=1;i<12;i++){
$('#a'+i).bubbletip($('#tip'+i), { deltaDirection: 'right' });
}
});
</script>
code in header part
<?php
foreach($this->nominations as $nomination)
{
for($i=1;$i<12;$i++){
if($nomination['award'.$i]!=""){?>
<div id="tip<?php echo $i?>" style="display:none;">
<div class="star"><strong><?php echo $nomination['award'.$i];?></strong></div>
<div><strong>Project: </strong><?php echo $nomination['project'.$i]?></div>
</div>
<?php }}
for($i=1;$i<12;$i++){
if($nomination['award'.$i]!=""){
echo "<span id='a$i'>";
echo "<img src='/public/assets/images/icons/star.png'/>";
echo "</span>";
}}
}?>
code in body section
My problem is when take my mouse over the stars of first iteration of foreach everything is working fine but its not working from second iteration i found that problem is with id a,tip becuause they are always becoming a1,a2.. and tip1,tip2... is there any solution
it is because every iteration of your forach loop creating elements of same id from a1 t a12
you need to put another level in names of ids .Try to use following
<?php
$count=0;
foreach($this->nominations as $nomination)
{
$count++;
for($i=1;$i<12;$i++){
if($nomination['award'.$i]!=""){?>
<div id="tip<?php echo $i?>_<?php echo $count?>" style="display:none;">
<div class="star"><strong><?php echo $nomination['award'.$i];?></strong></div>
<div><strong>Project: </strong><?php echo $nomination['project'.$i]?></div>
</div>
<?php }}
for($i=1;$i<12;$i++){
if($nomination['award'.$i]!=""){
echo "<span id='a$i_$count'>";
echo "<img src='/public/assets/images/icons/star.png'/>";
echo "</span>";
}}
}
<input type="hidden" id="total_iteration" name="total_iteration" value="<?php echo $count?>"/>
?>
And change you javascript code accordingly
<script type="text/javascript">
$(document).ready(function() {
var total=$('#total_iteration').val();
var t=0;
for(t=1;t<total;t++)
{
for(i=1;i<12;i++){
$('#a'+i+'_t').bubbletip($('#tip'+i+'_'+t), { deltaDirection: 'right' });
}
}
});
</script>
After some debigging above code should run the way you want i haven't tested it but i guess the main problme is the elements of duplicate ids in each foreach iteration
I am using galleria slider as a jquery slider nd jwplayer to display videos. Problem is that it does not display the jwplayer in the slider, it just displays a black square. I got it working for images but can't get it working for the video player jwplayer. Can somebody who knows how to do this modify the code below so it is working in my app?
Galleria: http://galleria.io/docs/
jwplayer: http://www.longtailvideo.com/jw-player/
<?php if(count($arrVideoFile[$key]) > 1){ ?>
<style>
#galleriavideo_<?php echo $key; ?>{ width: 500px; height: 300px; background: #000 }
</style>
<div id="galleriavideo_<?php echo $key; ?>">
<?php foreach ($arrVideoFile[$key] as $v) { ?>
<div id="myElement-<?php echo $key.'-'.$i; ?>">Loading the player...
<script type="text/javascript">
jwplayer("myElement-<?php echo $key.'-'.$i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>",
width: 480,
height: 270
});
<?php $i++; ?>
</script>
</div>
<?php } ?>
</div>
<script type="text/javascript">
Galleria.loadTheme('jquery/classic/galleria.classic.min.js');
Galleria.run('#galleriavideo_<?php echo $key; ?>');
</script>
<?php } ?>
It is a bit strange, another user posted an extremely similar question here: Having trouble using iframes
Anyway, I will try to post a solution close to your code. I presume you want one slider with multiple videos.
You need two files: video.php, a page showing a video according to a certain filename and gallery.php, the page containing the slider.
video.php:
<?php
$v = filter_input(INPUT_GET, "v", FILTER_SANITIZE_STRING);
?>
<div id="container"></div>
<script type="text/javascript" src="/path/to/jwplayer.js"></script>
<script type="text/javascript">
jwplayer("container").setup({
file: "VideoFiles/<?php echo $v; ?>",
width: 480,
height: 270
});
</script>
gallery.php:
<?php if(count($arrVideoFile[$key]) > 1){ ?>
<div id="galleriavideo" style="width:500px; height:300px; background:#000;">
<?php
foreach($arrVideoFile[$key] as $v) {
$vurl = "/path/to/video.php?v=".rawurlencode($v);?>
<img class="iframe">
<?php } ?>
</div>
<script type="text/javascript" src="/path/to/jquery.js"></script>
<script type="text/javascript" src="/path/to/galleria.js"></script>
<script type="text/javascript">
Galleria.loadTheme('/path/to/galleria.classic.min.js');
Galleria.run('#galleriavideo');
</script>
<?php } ?>
I wonder whether someone may be able to help me please.
The code below allows users to delete images from a gallery.
Full Script Minus Styling
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
//echo $_SESSION['userid'];
//echo $_SESSION['locationid'];
?>
<?php
$galleryPath = 'UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=0.3">
<title>Galleria Twelve Theme</title>
<style>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script src="galleria/galleria-1.2.7.min.js"></script>
<script src="galleria/themes/twelve/galleria.twelve.min.js"></script>
<script src="galleria/plugins/history/galleria.history.min.js"></script>
<link rel="stylesheet" href="galleria/themes/twelve/galleria.twelve.css">
<style>
.galleria-thumbnails .btn-delete {
display: block; /* Or just use a div instead of a span*/
position: absolute; bottom : 0px; /*align at the bottom*/
width: 80px;
height: 17px;
cursor: pointer;
background: url(trash8.gif) no-repeat bottom; }
</style>
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var userid=$(".hiddenvals").attr('userid');
var locationid=$(".hiddenvals").attr('locationid');
// send the AJAX request
$.ajax({
url : 'delete3.php?userid='+userid+'&locationid='+locationid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
</head>
<body>
<ul id="navigation">
<li class="left">
<div align="center">← Add Images</div>
</li>
</ul>
<form id="viewimages" name="viewimages" class="page" action="index.php" method="post"> <input name="userid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['userid']; ?>"> <input name="locationid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['locationid']; ?>"></form>
<div class="content">
<h1>Galleria Twelve Theme</h1>
<p>Demonstrating a simple example.</p>
<!-- Adding gallery images. We use resized thumbnails here for better performance, but it’s not necessary -->
<div id="galleria">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
?>
<img data-title="<b>Image Name: </b> <?php echo $name; ?>" data-description="<b>Description:</b> <?php echo $description; ?>" src="<?php echo $source; ?>">
<?php endfor; ?>
</body>
</html>
In essence, the user clicks on a delete icon, then the 'delete.php' script called in the code above deletes the image from the server. This all works well.
What I'm struggling with is how to pass two variable values to the 'delete.php' script. These are 'userid' and 'locationid'.
I've tried adding the following to the beginning of my 'delete.php':
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
But the values are not carried over. I suspect that this may be down to the fact the the forms 'POST' action is being used to navigate to another HTML page, although I'm no expert, so I may have got this wrong.
I've done quite a bit of reading and searched for tutorials on how to go about getting around this problem, but I've not found anything that seems to suggest a solution.
I just wondered whether someone may be able to look at this please, and offers some guidance on how I can pass these two values to my 'delete.php' script.
Many thanks and kind regards
If they are in the html page add them to the ajax request:
{ image : img.attr('src'), userid: "VALUE", locationid: "VALUE"},
Try to send ids from your html page like
$.ajax({
url : 'delete.php?userid=2&locationid=4',
........
Then in php
$uid=$_POST['userid'];
$locid=$_POST['locationid'];
If you want to get userid and locationid dynamically for each image.
FIRST; in you btn-delete class add uid and locid attribute. I suppose you are looping through PHP.
LIKE ===>
<input type="button" class="btn-delete" uid="2" locid="5">
Then in your script
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var uid=$(this).attr('uid');
var locid=$(this).attr('locid');
// send the AJAX request
$.ajax({
url : 'delete.php?userid='+uid+'&locationid='+locid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
var id=$(this).attr('id');
var userid=$('#userid').val();
var locationid=$('#locationid').val();
$.ajax({
url : 'delete.php',
type : 'post',
dataType : 'json',
data : { image : img.attr('src'), userid: userid, locationid: locationid},
,
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
add dataType : 'json' and get posted value in delete.php by
$userid=$_POST['userid'];
$locationid=$_POST['locationid'];