Forum Moderators: coopster

Message Too Old, No Replies

PHP initiate file download

         

andrewsmd

5:23 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone know how I can initiate a file download. Basically I have a mp4 file embedded but I would like a link that says if your movie does not play click here to download. Also, is there anyway I can check if they have a quicktime plugin with PHP also? Thanks,

eelixduppy

5:47 pm on Jan 28, 2009 (gmt 0)



>> quicktime plugin

No, you aren't going to be able to tell this with PHP as PHP is a server-side technology.

As for the file download, you have to change the response headers appropriately for the file for the download to occur properly. Something like the following, actually:


header('Content-type: audio/mp4');
header('Content-Disposition: attachment; filename="audio.mp4"'); /* This is key to download dialog */
[url=http://www.php.net/readfile]readfile[/url]('/path/to/audio.mp4');

andrewsmd

6:16 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm still not following. I tried putting in the headers and had no luck. here is my code
Header("Content-type: audio/mp4");
Header("Content-Disposition: attachment; filename='myMovie.mp4'");
readfile("urlToMyMovie");

A few questions, first this is a video do I need to change the audio to video. I also notices some headers that were "video/quicktime" do I need to do that instead.

eelixduppy

6:55 pm on Jan 28, 2009 (gmt 0)



Ah, yes, it should actually be video:

Content-type: video/mp4

andrewsmd

7:15 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That did it. I actually realized I had the word attachment spelled wrong. That was why it didn't work. The information you gave me the first time was correct minus the audio/video change. Thanks,

andrewsmd

8:04 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a new question so I am trying to send a wmv download. I get the prompt and the download runs, but when you try to open the wmv file media player says that it is a corrupt file. Here is my code.
Header("Content-type: video/x-ms-wmv");
Header("Content-Disposition: attachment; filename=\"myFile.wmv\"");
readfile("myFile.wmv");

eelixduppy

8:22 pm on Jan 28, 2009 (gmt 0)



Make sure no extra white space, HTML, or anything but what's in the file is being sent to the browser otherwise you will get errors. That includes white space before the <?php tag.

andrewsmd

8:49 pm on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had <html> tags at the beginning and end. I didn't even think of that. Thanks,