[PHP] Downloading Videos in different formats in PHP

How to Download the videos in the user browser if a link is clicked??The problem is if a user clicks on a youtube video link it starts streaming the video but i want it to download the video in user browser. Here are the screen shots.

Here is the screen shot of streaming video.

You don’t need PHP for this. The download attribute has pretty good browser support.

For example

<a href="http://example.com/somefile.mp3" download="Music.mp3">

This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want). There are no restrictions on allowed values, though / and \ are converted to underscores. Most file systems limit some punctuation in file names, and browsers will adjust the suggested name accordingly.

From YouTube’s Terms of Service:

you agree not to access Content for any reason other than your personal, non-commercial use solely as intended through and permitted by the normal functionality of the Service, and solely for Streaming. “Streaming” means a contemporaneous digital transmission of the material by YouTube via the Internet to a user operated Internet enabled device in such a manner that the data is intended for real-time viewing and not intended to be downloaded (either permanently or temporarily), copied, stored, or redistributed by the user.


9.1 With the exception of Content submitted to the Service by you, all other Content on the Service is either owned by or licensed to YouTube, and is subject to copyright, trade mark rights, and other intellectual property rights of YouTube or YouTube’s licensors. Any third party trade or service marks present on Content not uploaded or posted by you are trade or service marks of their respective owners. Such Content may not be downloaded, copied, reproduced, distributed, transmitted, broadcast, displayed, sold, licensed, or otherwise exploited for any other purpose whatsoever without the prior written consent of YouTube or, where applicable, YouTube’s licensors. YouTube and its licensors reserve all rights not expressly granted in and to their Content.

Presumably you have their prior, written consent for this. Did they not give any guidelines or indications on how to go about it?

1 Like

@TechnoBear I know about that but i am making it for a client. Can you help me out of it.?

For a client?

That will be a bit tricky then.

The client will need to get written permission and the pass the information about how to do it to you.

Hopefully nothing gets lost in the translation.

And does the client have the necessary permissions?

My point here is that YouTube provides a streaming service and specifically states you may not download content, so I imagine they have things set up in such a way as to make it difficult to circumvent those rules - hence the problem you are having.

If they grant permission for content to be downloaded in certain circumstances, then presumably they also offer a method for so-doing.

If you do not have permission to do this, then you’re asking for help in breaking the TOS of another site, which is not something we would allow here.

The cynic in me says yes - for a fee. But maybe not.

From 5B (my bold)

Content is provided to you AS IS. You may access Content for your information and personal use solely as intended through the provided functionality of the Service and as permitted under these Terms of Service. You shall not download any Content unless you see a “download” or similar link displayed by YouTube on the Service for that Content. You shall not copy, reproduce, distribute, transmit, broadcast, display, sell, license, or otherwise exploit any Content for any other purposes without the prior written consent of YouTube or the respective licensors of the Content. YouTube and its licensors reserve all rights not expressly granted in and to the Service and the Content.


You can always download MP4 files of videos that you’ve uploaded.

1 Like

All right @TechnoBear. I would not ask such questions here. I have one more question if they do not allow downloading files from youtube.com then there should not be any extensions and downloading youtube video can’t they flush them when they access to youtube.com

@Mittineague it works fine in Chrome and Microsoft Edge but not working in safari and Mozilla Browser. Any Alternative way for other browsers? Btw thanks for help.

From what I hear of download extensions and the like, they tend to work for a certain amount of time, until Youtube can detect the downloader and take steps to block it. Then a new approach is required. So if you figure out how to write one, keep in mind that aside from breaking the ToS, you’ll also probably only get a short time before it’s “found” and blocked.

I have completed my research. It won’t get blocked. I can tell you many downloaders which are working since 10 years … keepvid.com is one of them.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.