PHP code cannot be executed in the browser. PHP can run through a PHP interpreter which you can install or on the server side of an HTTP server setup to process PHP (virtually all Web hosting packages provide this opportunity). As the code you are trying to use starts with "<?php", it means that it was developed to run in a Web application on a server side. Moreover, it is designed to serve as a response to some HTTP request, but the page or anything sending a request is not shown. The code does next to nothing; looks like a small fragment of something.
This code is practically useless for you, no matter what your purpose is. First of all, you should understand how Web works; but your question shows that at this moment you have no clue… Maybe we could help you if you explain your purpose.
[EDIT]
To download any file from an HTTP server, you have to send an HTTP request to it. If a file is big, you have a possibility to indicate in a request from what offset to start and what size of the block to download (partial download), and repeat it appropriate number of times. A Web server does it for you just on a click of an anchor element pointing to a file to download. Would it be enough for you?
If you really need to download a file using PHP on a server side, to a file on a server side, the answer depends on where is the source file. If it is on your host (under the root directory set up for your Web site), there is nothing to download, you just need to read this file, but you may need to force downloading it on client's request. Please see:
http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php[
^].
See also:
http://www.php.net/manual/en/function.readfile.php[
^].
If you need to download a file from some other site, you can open the file and write it to the output (whatever it is, could be the . The problem, again, is when the file is big, then reading it to memory can exhaust the available RAM. To read the file piece by piece, you can just open input stream, as the line you show does:
$download_video_file = file_put_contents($file_path, fopen($url, 'r'));
This line put the content of the file directly to the content of the HTTP response. Also, you need to determine right HTTP header (commented-out in your code). Please see:
http://www.php.net//manual/en/function.header.php[
^].
To correctly define a content type, please see where they are standardized:
http://en.wikipedia.org/wiki/Content_type[
^];
the standard types are supported by IANA here:
http://www.iana.org/assignments/media-types[
^].
See also:
http://en.wikipedia.org/wiki/Internet_Assigned_Numbers_Authority[
^].
In PHP resource like that one, you whole PHP page is "substituted" instead of the "real" file to be downloaded, possibly doing some job on the fly. To put it to work, you need an HTTP request to request this page, say, HTML with the anchor. Usually, it is done of some calculation of the content is done on the page (such as creation of graphics). For example, such script can calculate the URI to be downloaded from, based on some algorithm. I have no idea why would you need this, because, to let the user download some file, you could directly give the user it's URI. You need to do the calculations on the server side only if you need to do something special.
—SA