I have setup a video website but i need help to make $target_file change to the file url but it won't because it is in '' brackets and also at $stringdata
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$myFile = "/home/darlpsou/video.darlingserver.com/$target_file.html"; // or .php
$fh = fopen($myFile, 'w'); // or die("error");
$stringData = '<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/$target_file" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>';
fwrite($fh, $stringData);
fclose($fh);
There are various ways to do this. One would be to use sprintf:
$stringData = sprintf('<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/%s" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>',
urlencode($target_file)
);
Another would be to use HEREDOC syntax:
$stringData = <<< HTML
<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/$target_file" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>
HTML;
Yet another would be to concatenate the variable:
$stringData = '<h1>Title</h1>
<p> </p>
<p><video tabindex="0" poster="thumb.png" autoplay="autoplay" loop="loop" controls="controls" width="842" height="417">
<source src="http://video.darlingserver.com/' . urlencode($target_file) .'" type="video/mp4" />
<iframe title="YouTube video player" width="842" height="417" src="http://www.youtube.com/embed/iYuG55vOIVc" frameborder="0" allowfullscreen="allowfullscreen">
</iframe></video></p>';
This is really strings 101 so please refer to http://php.net/strings for additional clues.
Related
Using PHP, how do I recursively loop through a directory of mp4 files and convert the output to produce a page containing embedded HTML5 videos?
The PHP code that I'm working with is:
$files = scandir('folder/');
foreach($files as $file) {
//do your work here
}
<video width="400" controls>
<source src="mov_bbb.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
It is possible
so the code will be something like this:
<?php
$videodir = opendir('video_directory');
while(false !== ($filename = readdir($videodir))){
echo '
<video width="400" controls>
<source src="video_directory/'.$filename.'" type="video/mp4">
Your browser does not support HTML5 video.
</video>'
}
?>
If your intent is to simply mix the PHP logic and HTML together than the code is simply:
$files = scandir('folder/');
foreach($files as $file) {
echo '<video width="400" controls>
<source src="' . basename( $file ) . '" type="video/mp4">
Your browser does not support HTML5 video.
</video>';
}
Although I find it cleaner to have the logic in a separate file and do it like this:
<?php foreach($files as $file) { ?>
<video width="400" controls>
<source src="<?=basename( $file )?>" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<?php } ?>
However both are valid and only preference.
Keep in mind of the security of this issue. For example if a different file is in this directory, this could cause a security issue.
HI guys i am trying to get the image/video filename from path
Here i have paths in my php variable like this from database
E:/xampp/htdocs/pes/new/movie.mp4
E:/xampp/htdocs/pes/new/flowers.jpg
And i am trying to get new/movie.mp4 or new/flowers.jpg from above paths and display it in img tag or video tag
<img src="new/flowers.jpg" alt="Trulli" width="500" height="333">
or
<video width="400" controls>
<source src="new/movie.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
Can anyone help me how to do that
Thanks in advance
Hope this will help you :
Set your base_url in your config.php
$config['base_url']='http://localhost/pes/'
and ur image src should be like this :
<img src="<?=site_url('new/'.$image); ?>" alt="Trulli" width="500" height="333">
Try with base_url(). Set your base_url in config.php for example www.xyz.com/ Update your code like this:
<img src="<?php echo base_url() ?>new/flowers.jpg" alt="Trulli" width="500" height="333">
And video frame:
<video width="400" controls>
<source src="<?php echo base_url() ?>new/movie.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
Hope this will help you!
If all paths are relative to FCPATH, FCPATH = 'E:/xampp/htdocs/pes', you can use:
<img src="<?php echo base_url(str_replace(FCPATH, '', 'E:/xampp/htdocs/pes/new/flowers.jpg')) ?>" alt="Trulli" width="500" height="333">
or
<video width="400" controls>
<source src="<?php echo base_url(str_replace(FCPATH, '', 'E:/xampp/htdocs/pes/new/movie.mp4')) ?>" type="video/mp4">
Your browser does not support HTML5 video.
</video>
I have try to add youtube video on my page but its give error mime type can you please help me to resole this
<div class="footer-inner-outer contact-dlc">
<video width="320" height="240" controls="controls">
<source src="https://www.youtube.com/embed/EPeLTYFlgv0" type="video/webm" />
Your browser does not support the video tag.
</video>
</div>
<div class="footer-inner-outer contact-dlc">
<iframe width="320" height="240" src="https://www.youtube.com/embed/EPeLTYFlgv0" frameborder="0" allowfullscreen></iframe>
</div>
I need help. I have a file "video.php"
Where it contains an html5 player.
I want instead
www.mysite.com/myvideo.mp4
Be it
Www.mysite.com/video.php?file=myvideo.mp4
I want the src of the video to change according to what is typed in the url.
video.php
<video width="480" height="320" controls>
<source src=" **Name typed in the url** " type="video/mp4">
</video>
This will work:
<video width="480" height="320" controls>
<source src="<?php echo $_GET['file']?>" type="video/mp4">
</video>
I'm new to PHP. Everything else works on my site okay but I seem to have an issue with this particular piece of code. The $efn is my file name, and I need to retrieve it from a MySQL database but this code doesn't seem to work. It works in a normal video container but not when using the if statement.
Any ideas how to fix this?
<?php
$video_container = substr($efn, -3);
if ($video_container == 'mp4') {
echo '<video preload="auto" width="640" height="264" poster="../images/<?php echo $thumb ?>" controls="controls" autoPlay="false">
<source src="<?php echo $efn ?>" type="video/mp4">
</video>';
}
else {
echo '<video height="620" width="480" controls>
<source src="<?php echo $efn ?>" type ="video/avi" />
</video>';
}
?>
You have syntax problem when printing the string. Replace the <?php echo $fn ?> section by ' . $efn . '
Like this:
$video_container = substr($efn, -3);
if ($video_container == 'mp4') {
echo '<video preload="auto" width="640" height="264" poster="../images/<?php echo $thumb ?>" controls="controls" autoPlay="false">
<source src="' . urlencode($efn) . '" type="video/mp4">
</video>';
}
else {
echo '<video height="620" width="480" controls>
<source src="' . urlencode($efn) . '" type ="video/avi" />
</video>';
}