How to play audio file retrieved as blob file in php? - php

I want to play the audio file while is retrieved from the mysql database as blob file in php. But when i run the file, the php file is downloaded.
Here is my code
<?php
$file_path = "H:\\uploader\\John.mp3";
?>
<audio src="<?php echo $file_path;?>" preload="auto" />
can anyone help me to solve this problem.

You're not showing any examples of what you're tried with mysql, but maybe this will point you in the right direction:
http://php.net/manual/en/pdo.lobs.php
Edit:
Try including the embed element:
<?php
$file_path = "H:\\uploader\\John.mp3";
?>
<audio controls>
<source src="<?php echo $file_path;?>" type="audio/mpeg">
<embed height="50" width="100" src="<?php echo $file_path;?>">
</audio>

Related

<img> tag is not working in php Codeigniter

<img> tag is not working in PHP Codeigniter
<img src="<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />
Output of $p_info['p_img'] is giving correct path where image is saved.
and i uploaded the image now i want to show that image in edit process
<img src="<?php echo $p_info['p_img']; ?>"
alt="Product Image is not uploaded" height="700px" width="500px" />
<?php echo $p_info['p_img']; ?> should be a path which access images from the project directory not from a local path.
C:/xampp/htdocs/squadfreetry/assests/img/products_images/Acne Free (1).jpg this is wrong & will not show image.
You have to save image path starting from /assests/... and to access it by calling base_url() at first & followed by saved path in DB.
Code should be like:
<img src="<?=base_url().$p_info['p_img'];?>"
alt="Product Image is not uploaded" height="700px" width="500px" />
Where $p_info['p_img'] is a path starting from /assests/..
Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.
If you want a shorter tag, use this:
<?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>
Here is detailed information:
https://codeigniter.com/user_guide/helpers/html_helper.html#img
More examples:
<img src="<?php echo base_url('assets/uploads/' . $gambar)?>" alt=""/>
and
<img src='<?php echo base_url("assets/uploads/$gambar")?>' alt=""/>
Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
Please try the below way:
I am assuming that your project folder is Cart -> images/your desired image
when you do file uploading then you have to save the image in folder -> images
and the image name in database.
so to access it replace your image code like this:
<img src="<?php echo base_url(); ?>images/<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />
On CodeIgniter 4 you can use the img function, from html helper.
Adds the helper on controller -> helper('html');
Generates the img tag on the view -> echo img('public/img.png').

Stream a video file with variable name using php

This is my html
<div align="center" class="embed-responsive embed-responsive-16by9" width="640" height="480">
<video autoplay loop class="embed-responsive-item" controls>
<source src="/projects/moviestream/php/stream.php">
</video>
</div>
and my stream.php
// class definition of video_stream
$stream = new VideoStream($video_link);
$stream->start();
My question is how to pass the variable $video_link from my html to the php page so it streams the correct video?
Found a solution using just plain php!
I use a kind of php router that allows me to route movie/1 to VideoStreamer and invoking the method stream($id) wwith $id set to 1

Play audio tag with blob inside on mobile

i've made this script:
<?php
if(!empty($dati['audio'])) { ?>
<span>
<audio id="audio_player" src="data:audio/mp3;base64,<?php echo base64_encode($dati['audio']);?>" controls="controls" autobuffer="autobuffer">
</audio>
</span>
<?php } ?>
It create an audio tag with a blob value inside..it work in every browser on pc but it won't work on some mobile browser..i've tried with external library to play audio in different way but it look like no one allow blob instead of the path of the file..someone have an idea which can help me to solve this problem?
replace data:audio/mp3 to data:audio/mpeg
This link will be useful too.
If not working. Try this onle also.
<audio id="audioFile" controls="controls" loop="loop" autoplay="autoplay" >
<source src="filename.mp3" type="audio/mpeg" />
<source src="filename.ogg" type="audio/ogg" />
</audio>
Hope it will work for you :)

i am generating the pdf using mpdf from html and now i have to show pdf inside pdf

show pdf inside pdf
i am generating the pdf using mpdf from html, the problem that i am facing its that i have images and i can show them using img src, but i need to show the pdf inside the pdf
i have pdf files that i have to show inside the pdf file
with href the user can download the pdf inside the the report pdf file
any ideas?
this is the code i tried so far a nothing seems to work :
Download PDF
<embed src="<?php echo base_url().'get_image.php?i='.$plan_dir.$plan['file'];?>" width="500" height="375">
<embed src="<?php echo base_url().'get_image.php?i='.$plan_dir.$plan['file'];?>" width="500" height="375">
<div id="pdf">
<object width="400" height="500" type="application/pdf" data="<?php echo base_url().'get_image.php?i='.$plan_dir.$plan['file'];?>" id="pdf_content">
<p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>
</div>
<object data="<?php echo base_url().'get_image.php?i='.$plan_dir.$plan['file'];?>" type="application/pdf" width="300" height="200"> alt : test.pdf
</object>
<iframe src="http://docs.google.com/gview?url=<?php echo base_url().'get_image.php?i='.$plan_dir.$plan['file'];?>&embedded=true" style="width:718px; height:700px;" frameborder="0"></iframe>
Try using URL with http, for example:
http://example.com/image.jpg or http://127.0.0.1/project/image.jpg
instead of base_url()...
To use the link, try using name
For example:
<a name="http://example.com" target="_blank">DESCRIPTION</a>

How to create video player in php with play & fullscreen button?

I have got the below code from internet for embedding a video player but it doesn't have play/pause button or fullscreen option.
Here is the code:
<OBJECT ID="MediaPlayer" WIDTH=320 HEIGHT=342
CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Windows Media Player components..."
TYPE="application/x-oleobject">
<PARAM NAME="movie" VALUE="<?php echo $path.'/'.$_POST['file']; ?>">
<EMBED TYPE="application/x-mplayer2"
SRC="<?php echo $path.'/'.$_POST['file'];?>"
NAME="MediaPlayer"
WIDTH=320
HEIGHT=342>
</EMBED>
</OBJECT>
Any code fix please?
<OBJECT ID="MediaPlayer" WIDTH="300" HEIGHT="200" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">
<PARAM NAME="FileName" VALUE="<?php echo $path.'/'.$POST_['file']; ?>">
<EMBED TYPE="application/x-mplayer2" SRC="<?php echo $path.'/'.$POST_['file']; ?>" NAME="MediaPlayer" WIDTH="200" HEIGHT="200" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="0"></EMBED></OBJECT>
Better use some free flash based player and embed this on the website, this code you have pasted here - with windows media player - works very badly.
Beside it's very insecure. Easy to do cross site scripting if you don't filter _POST/_GET/
http://www.longtailvideo.com/players/jw-flv-player/
Users may need plugin to display media player in other browsers other than internet explorer. I recommend you to use a flash based player.
http://www.longtailvideo.com/players
{
<video width="720" height="430" autoplay *controls preload="none*">
<source src="" type="video/mp4">
<source src="" type="video/ogg">
//Your browser does not support the video tag.
</video>enter code here
}
add controls

Categories