Hi Guys,

Anybody tell or give me the code for show and play video in PHP.

Reply as soon as possible.....

Dani AI

Generated

Short answer: PHP runs on the server and does not "play" video in the browser. It generates HTML (or streams bytes) so the browser or a JS/HTML player does the actual playback. was right to point out the distinction, and 's Flash-player suggestion was common in 2010 — today prefer the HTML5 video element or a modern JS player for consistent behavior across devices.

A simple, modern embed (put this in the page PHP outputs):

<video controls width="640" poster="thumb.jpg">
  <source src="/videos/movie.mp4" type="video/mp4">
  <source src="/videos/movie.webm" type="video/webm">
  Your browser does not support the video tag.
</video>

If you need to choose files dynamically from PHP, generate the markup server-side but validate input (whitelist filenames, use basename(), escape output). Example pattern:

<?php
$file = basename($_GET['file']); // validate against an allow-list in real code
$url  = '/videos/' . $file;
echo '<video controls poster="thumb.jpg">';
echo '<source src="'.htmlspecialchars($url, ENT_QUOTES).'" type="video/mp4">';
echo '</video>';
?>

Practical notes and troubleshooting:

  • Encode files in web-friendly formats (H.264+AAC in MP4 is widely supported; WebM is a good alternative). Use FFmpeg to transcode if needed.
  • Let the web server serve static files where possible. If PHP must stream large files, implement Range support or use server features like X-Sendfile / X-Accel-Redirect to avoid high memory/CPU.
  • Common problems are wrong MIME types, file permissions, lack of Accept-Ranges (no seeking), and invalid paths — check the browser network panel.
    Further reading: HTML5 video element (MDN) and PHP file-serving functions (HTML5 video element, readfile() / headers).

Recommended Answers

All 4 Replies

This one is very good player to integrate.

Try this out.

You can not play videos with PHP, You have to use flv player or other video players. OK!

can you please give me some idea or code kind of thing how to i do this

Hi shailendra,
download flv player from :

Now You will get one readme.html file.
Here you will find embeded code to play file.
and you will find file=video.flv , video.flv is file to play.
Now all you need is to dynamically add ur file here using php tag.

e.g. <param name="flashvars" value="file=<?=$myfile;?>&image=preview.jpg" />

Now copy all files which are used in demo and insert in your website's directory structure to work it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.