This is kind of stupid question but is there any way to play videos just by using two pages, I mean like instead of creating an html page for every video I upload to my website, can I have only two php pages and then pass the video from the first page and play on the second one?
I know about passing variables in url but I am kinda confused on how to do this.
I actually embedded my videos from google drive and have a format like
<iframe src="https://docs.google.com/file/d/0B5ZMsnZoUVNSWHhxeGc/preview" width="640" height="385"></iframe>
would it be possible to do like
<a href="play.php?video='test.mp4'>Click to play</a>
or like
$video= 'test.mp4';
<a href="play.php?vid='$video'>Click to play</a>
play.php
$video = $_GET['vid']
if(!empty(($video)){
//then play the video here.
}
I'm expecting you're usnig HTML5.
Let's say there's a list of videos on the first page, and you click on a name of video and it redirects you to second page. Pass the video url (or any identifier for server to know which video) in the link. You can do it like
Cats!!
This will send vid_url as a GET variable on second page. page2.php is, as you can imagine, very simple
<?php
$vid = $_GET['vid'];
//echo $vid;
echo "<video width='320' height='240' controls>
<source src=".$vid." type='video/mp4'>
Your browser does not support the video tag.
</video>"
?>
Of course, you'll do something more elaborate than simply using "echo" for formatted HTML output.
Yes. Instead of empty use isset:
if (isset($_GET["vid"])){
$video = $_GET['vid'];
//play video
}
Play This Video
And On Play.php page add this code
if(isset($_GET['video'])&&!empty($_GET['video']))
{
$Video = $_GET['video'];
// Use the Source of your video anyway you like to play the video
}else
{
echo 'No video selected to play';
}
Related
Good afternoon friend,
I am trying to be able to take the video from the url of the iframe, from what I see I have to first click the video so that the video element is visible in html.
Isn't there a way to automate the process? Click automatically when entering the url and extract the url from the video
The url is: https://feurl.com/v/2625zf2pddy2ge
I'm supposed to get the following url from the video at the end.
https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0
My code is:
<?php
$data = file_get_contents('https://feurl.com/v/2625zf2pddy2ge');
preg_match('/<video[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', $data, $matches);
$video = $matches[1];
echo $video;
?>
Both links dont work but assuming html looks something like this a.html:
<video width="320" height="240" src="https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0"></video>
Try this:
<?php
$data = file_get_contents('a.html');
preg_match('/<video.*?src="(.*?)"/', $data, $matches);
var_dump($matches[1]);
Output:
string(279) "https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0"
If it doesnt work dump your $data and make sure the video tag is even there. Sometimes this is loaded later via ajax, so it is not even available in initial response.
I have Work with PHP project in which one php page has so many category wise videos display and play but what I want is :-
I play first video it will start play and after that i click on second , third videos then all of the videos are playing, i want to stop previous video when i click on second and stop second video when i click on third and so on like that.
<?php
include("admin/dbconn.php");
$sqlAdmin ="SELECT * FROM `tbl_videos` where video_category='$rows[0]'";
$exeAdmin = mysqli_query($conn,$sqlAdmin);
$administration="";
while($arr=mysqli_fetch_array($exeAdmin)){
$video_link = $arr['video_link'];
$newId = explode("?v=",$video_link);
echo $administration.="<iframe src='https://www.youtube.com/embed/$newId[1]' frameborder='0' allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>
";
}
?>
Starting the different videos within the iframe is done on the client side and not server side and thus you will not be able to control the behaviour via PHP.
You can, however, do it via Javascript.
Have a look here for example
Stop embedded youtube iframe?
Working on a project that involves people signing up to the website and uploading a video, the thing is I have created a file upload form and it works perfectly, I head over to the database and check the users table and I see the video uploaded I then head into my PHP code and initialize the variable:
$Getvid = " ";
Then I fetch the row
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) { $vid = $row ["vid"]; }
After that I place
$Getvid = '< source src="user/'.$u.'/'.$vid.'" >';
if($vid == NULL) {
$Getvid = '< source src="image/Movie on 2013-07-24 at 13.43.mov" type="video/mp4" >';
}
To get video files that a user have uploaded and echo it out on he/she page and also if the vid row is null then the script would show a default video that I have stored in the database
After that I echo out the video on the users page
< video width="320" height="240" controls>
< source src="< ?php echo $vid; ? > " >
</video>
But for some reason the video doesn't show also the default doesn't work unless I source it specially like this:
<video width="320" height="240" controls>
<source src="image/Movie on 2013-07-24 at 13.43.mov" type="video/mp4" >
</video>
PHP will not be invoked if you're actually typing < ?php in the source code. It will need to be in a single tag, such as <?php. When you have fixed that, compare the output from the PHP code with your working example and see where it differs. If you want a more exact answer on that, add the generated HTML together with the HTML you're expecting to your question.
You're also using the same variable in different paths; one place you're appending image/ before the video name, while your variable doesn't seem to contain the path.
Two potential sources of the problem, you shouldn't store your files with spaces in their names and you haven't specified a type for your video.
The SRC should contain a valid URL and therefore you should have %20 or + in your PHP string in stead of the spaces.
Note: As mentioned by Fisk, your php tags are wrong due to the spacing. You use the PHP echo short-form by replacing
< ?php echo $vid; ? >
by
<?= $vid; ?>
i'm using shadowbox for my website to open the big images with clicking thumbnails as you know. My Problem is, i'm fetching the users' facebook profile photo like :
$large = "https://graph.facebook.com/{$id2}/picture?type=large";
$small = "https://graph.facebook.com/{$id2}/picture?type=square";
And it's working perfect, but in shadowbox i have problem with large image..
I'm calling this in shadowbox like :
<a href="<?php echo $large; ?>" rel="shadowbox">
<img style="max-width:50px; max-height:50p;" src="<?php echo $small; ?>" />
</a>
As you can imagine, small image is showing perfect, but when i click on the small image which has href, it fails to show the large image.
I've tried to change large image variable to this :
$large = "https://graph.facebook.com/{$id2}/picture?type=large&redirect=false";
but also it has failed to show the large image..
Hope you can help, thank you
I haven't worked with Shadowbox before, so I don't know how it works behind the scenes. It may be that it can't deal with a url that returns another url for the large image.
Try making the API call with php and then passing this result to shadowbox.
$large = file_get_contents("https://graph.facebook.com/{$id2}/picture?type=large&redirect=false");
Of course, using file_get_contents() like this is a quick and dirty method. If it works, before you roll this out to a production site, you'll want to use cURL or better yet the Facebook PHP SDK to do this.
Assuming you're using shadowbox to show multiple users' photos on a page, you'll probably end up bumping into the API limits at some point. To prevent this, redo your API calls to grab multiple photos in one shot:
$large_photos = $fb->api('/picture?type=large&redirect=false&ids=' .
implode($ids_array, ','));
https://graph.facebook.com/{$id2}/picture?type=large&redirect=false basically returns you a text content the URL of the image. That's why it's not showing.
Eg.
https://graph.facebook.com/yungsenriady.budiman.3/picture?type=large&redirect=false
returns
"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/157348_100001167523294_1569184886_n.jpg"
Try just use
https://graph.facebook.com/{$id2}/picture?type=large
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 :(
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:
1|blah|1
2|blahblah|0
Where the third '1' means video, and a '0' means photo? It's your metadata, so you can dictate its structure.
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:
<?php
$photos=file("photos.txt");
// since you already know the page number, you can just skip to that index instead of looping through the entire file
$item = explode("|",$photos[$page-1]);
$photo = trim($item[1]);
//lets see if it's a photo or a video
if(substr($photo,-3) == 'jpg') {
//echo out code for images here
} else {
//echo out code for video here
}
?>