Launch a video file via a PHP page

Kaorentin Posted messages 182 Status Member -  
avion-f16 Posted messages 19182 Registration date   Status Contributor Last intervention   -
Hello,

I set up a small local site to gather videos. So, we can navigate through the videos via their covers. I grouped all this in a MySQL database.

Anyway, that's just the context.

Here's my problem:

I want to open a video from the browser. However, after quite a bit of tinkering, I managed to launch a video, but there's no sound.

Here's the code used:

// page.php //

<?php echo "<a href='read.php?file=D:\Unwatched Films\video.avi'>"; ?>

// Here, we are on the video page in question, clicking the link opens read.php with the video parameter in question.

// read.php //

<?php
exec($_GET['file']);
?>

// It's that simple!

Do I need to add some info to tell it to play the audio as well? (It seems unbelievable!)

Thanks in advance for your answer!

Corentin.

Configuration: Windows 7 / Firefox 4.0.1

1 answer

avion-f16 Posted messages 19182 Registration date   Status Contributor Last intervention   4 511
 
Hello,

The exec() function is used to execute a command or a program.
https://www.php.net/manual/en/function.exec.php

Try using readfile() instead.
And if the sound issue persists, then it means that the browser does not have the necessary plugins to read the audio codec.
--
Thought leads the world.
0
Kaorentin Posted messages 182 Status Member 9
 
Thank you for your response!

Unfortunately, now when I launch the file, I have sound but VLC doesn't open anymore...
Well, it opens in the background, but doesn't display :/

And I can't bring it up :s

Is there a way to pass the execution of a program as a parameter to readfile? Something like readfile(exec(vlc), video.avi) (roughly speaking).
0
avion-f16 Posted messages 19182 Registration date   Status Contributor Last intervention   4 511
 
readfile() reads the file and returns it to the browser, just as if you were directly requesting the file from the browser, without going through PHP.

If you want to open VLC, then try this instead:
exec('C:\Path\to\vlc.exe C:\Path\to\video.avi');
Don't confuse it; it is not about specifying the two paths independently, but about specifying the VLC program which takes the file to open as a parameter.
0
Kaorentin Posted messages 182 Status Member 9
 
Yes, the exec you indicated is what I was doing originally, without success...
Always this sound problem! I can see the video that plays in VLC, but with no sound :/
(by the way, I say VLC, but it does the same thing with MPC and others).

And regarding the readfile that only plays the sound, I get this error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 734361601 bytes) in C:\wamp\www\cmdb\all\read.php on line 3

Knowing that my read.php only contains

<?php
readfile($_GET['file']);
?>
0
avion-f16 Posted messages 19182 Registration date   Status Contributor Last intervention   4 511
 
I just tried using exec() and it works very well.
<?php define('VLCBIN', '"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"'); define('MOVIE' , '"C:\Users\user\Desktop\test.avi"'); exec(VLCBIN.' '.MOVIE); ?>
The double quotes are there for a reason:
Single quotes are used to contain the string
And the doubles, which will be sent to Windows, are used to handle spaces in paths.
So Windows receives this (with no line break):
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "C:\Users\user\Desktop\test.avi"
0
Kaorentin Posted messages 182 Status Member 9
 
That's curious... I followed your instructions exactly, the same php file: vlc runs in the background, I can hear the movie, but I don't have a vlc window opening :/
Does vlc open for you?
0