html source path with variable [duplicate] - php

This question already has answers here:
use both html and php in echo and href line
(3 answers)
Closed 8 years ago.
I write a PHP - HTML project and a have to be able to depict some videos. Thus, I store the same of the video like this:
$myVideoName = "Video1.mp4" //video in local host
and I wrote a simple video script to embed it to a browser:
<div style="text-align:center">
<video id="Video1" width='500' height='500' controls >
<source src='.\MyProject\Video1.mp4' type='video/mp4'>
</video>
</div>
Now I want to embed the variable of the video to the source path code like this:
<source src='.\MyProject\'.$myVideoName type='video/mp4'>
What is the right way to do so?

Assuming the page which contains the video tag is of .php extension, to use variables inside a string, you can do something like this:
<source src=".\MyProject\<?php echo $myVideoName; ?>" type="video/mp4">

You could do it like this.
<?php
echo '<source src="\MyProject\'.$myVideoName.'" type="video/mp4">';
?>

If $myVideoName is not changing say $myVideoName = "Video1.mp4" then you will do like this :
<source src=".\MyProject\<?php echo $myVideoName;?>" type="video/mp4">
if the videos data is in some table then you have to fetch the data from that table to this variable $myVideoName
You have to save this file with extension .php otherwise it won't work

Related

Displaying image from different disk

Hi i want to show images from different disk.
Here is my code.
is it possible to do that ?
$a = "D:/img/1.jpg";
<img src="<?php echo $a; ?>" alt="...">
Im using this on my localhost.This is not for the web.
i add screenshot here.
when i come above the img it shows the link. but not show img. and i use lightbox.
but without lightbox its not show again.
example
The sample you provided/attached is only doable if you load the html file directly to your browser. It is not possible if you load it via localhost. In your case, you will have to do something like this:
<?php
$image = file_get_contents('D:/img/1.jpg');
$image_codes = base64_encode($image);
?>
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Reference: How to retrieve and show images from another drive using src attribute in <img> tag?
I'd suppose to use such URLs with protocol: $a = 'file:///D:/img/1.jpg';

PHP Video Url with GET

So I have a video player with the following source code.
<video width="320" height="240" controls>
<source src=<?php echo $tryOne; ?> type="video/mp4">
</video>
It will echo something something similar to below and insert it as the source video.
'176.227.210.66/Kuroko%20no%20Basket%202%20Episode%205.mp4?st=zEws3h1Xg-to07f3as6KqA&e=1385059955'
However, the player will not load the the video. If I open page source and copy the generate url into the address bar and hit enter, it will go to the direct url and load the video just fine. I think that the player won't load the url because it has GET variables in it, and I need to know how to fix this. Please tell me how I can load a video in a player from the above url with GET variables.
Note: the player will load a video just fine if it is named without the get variables.
As per the HTML specification for <video>, you need a valid URL:
src = non-empty URL potentially surrounded by spaces.
The URL for the video.
In this case, it is missing the protocol information (http://) and it is not being recognized as a video src. Change the value of $tryOne to include the protocol information or manually prepend it to the variable when outputting to the page. It might also be a good idea to URL-encode the string.
For example:
<video width="320" height="240" controls>
<source src=<?php echo 'http://'.urlencode($tryOne); ?> type="video/mp4">
</video>
Live demo.

Get video from database and displaying the video on a page directly without having to click a link

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; ?>

playing videos on second page php

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';
}

PHP - call a function from a img src [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Want to render an image without saving it to disk using PHP GD libs
The image cannot be displayed because it contains errors.
I'd like to call a function that make a image trought the img src tag. Is it possible?
I mean : instead of call <img src="path/file.php" /> I'd like to do somethings like <img src="function()" />
PHP is server side; It can generate either a base64_encoded image result which can be placed as an image, or you can point to a php script that will generate an image. But, regarding client side, it won't work.
So, you could do the following:
// the browser will make a call to your generator to render an image back
echo '<img src="myimagegenerator.php" />';
// src will be something like "data:image/png;base64,..."
echo '<img src="'.generateImage().'" />';
In HTML5 you can put the base64 encoded image source in an image tag. You will just need a function to return that.
function getImage($file){
return 'data:image/gif;base64,' . base64_encode(file_get_contents($file));
}
Your img tag:
<img src="<? echo getImage('path-to-image.gif'); ?>" />
No.
However, you can use the URL "thispage.php?makeimage=1" and call the function and output an image if $_GET['makeimage'] contains 1.

Categories