One way to download a YouTube video in PHP is using a library such as youtube-dl
. You can use exec()
or the Process
component from Symfony to execute the command-line tool.
Here is an example implementation that downloads a video from YouTube given its URL:
main.php463 chars17 lines
This code assumes that youtube-dl
is installed and available on the system. You can install it using apt-get install youtube-dl
(on Debian-based systems) or by downloading the binary from the official repository: https://github.com/ytdl-org/youtube-dl. The code also assumes that the user running the script has sufficient permissions to access the output directory.
gistlibby LogSnag