-4

I've got a mp4 file saved on external FTP server. When I save it over "Save video as" when I play this video in classic HTML5 player, everything is ok. But when I download this file over this headers:

header('Content-Description: File Download');
header('Content-Transfer-Encoding: binary');
header('Content-Length: FILE_SIZE');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header('Expires: Mon, 1 Apr 1974 05:00:00 GMT');
header("Content-type: video/mp4");
header("Content-disposition: attachment; filename=FILE_NAME");
readfile(FILE_URL); // do the double-download-dance (dirty but worky)

(FILE_SIZE, FILE_URL and FILE_NAME are filled correctly of course), than mp4 file is downloaded, but every player say something like "this format is not supported". When i download any other filetype (pdf/ppt,...), everything is ok.

Any ideas, pls??

Radim Kleinpeter
  • 108
  • 2
  • 11
  • I read all these topics: http://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php, http://stackoverflow.com/questions/14366424/force-download-mp4-files, http://stackoverflow.com/questions/15797762/reading-mp4-files-with-php, http://stackoverflow.com/questions/3128906/mp4-plays-when-accessed-directly-but-not-when-read-through-php-on-ios, http://stackoverflow.com/questions/5924061/using-php-to-output-an-mp4-video, http://stackoverflow.com/questions/9728269/content-length-and-other-http-headers,... but nothing helped me :X – Radim Kleinpeter Apr 28 '15 at 21:41
  • Do you mind post the URL of your video and let us replay the problem? – Shiji.J Apr 28 '15 at 22:12
  • http://www.vaseakademie.cz/kurz/kurzid:68/stihla-vyroba-bez-balastu - please click on the first red button "ukázka zdarma" on right side (free video - there you can try to download it over "Stáhnout lekci" - doesnt work, or over browser as "Save video as" - works ok) – Radim Kleinpeter Apr 28 '15 at 22:20
  • Hmm, just tested, compare the file you given (Stáhnout lekci) with the source of the demo video http://data.vaseakademie.cz/lekce/kurz_68/b55bf87383652751aeefd02f844f9fd9.mp4, the two mp4 files I downloaded are different files. thats why none of the players can play it. And I believe there is nothing wrong with the header, since headers can't modify the file content. My suggestion is, double check you script for preparing/processing the download file, not the header. – Shiji.J Apr 28 '15 at 23:15
  • Some of the headers you send are meaningless. Don't copy over code from broken tutorials. – Julian Reschke Apr 29 '15 at 06:43

1 Answers1

-1

File 1 (Wrong File, Not able to play):

http://www.vaseakademie.cz/ajax/s:lekceTools/c:lekceTools/m:getFile/loID:177

Through 'Stáhnout lekci'

Filesize: 50156182 MD5:ef0bf2fdfe1774c0a75d26202cdebdcd

File 2 (Correct File, able to play):

http://data.vaseakademie.cz/lekce/kurz_68/b55bf87383652751aeefd02f844f9fd9.mp4

From the source if the playing video. Same with right click, save video as

Filesize: 50156182 MD5:ef72631add8524d72ac1b61bacf0cc1a

Conclusion:

Nothing wrong with the header, the file content is different. You should check your script for file processing, not the header

Shiji.J
  • 1,561
  • 2
  • 17
  • 31
  • I opened and compare those files in NetBeans (I know, it's not the best solution, but worky)... that "bad" file has cca 6 empty lines on the begginig of the file (and some character on the end of file, but it is not so important I think)... where could be these empty lines added? – Radim Kleinpeter Apr 29 '15 at 10:52
  • have a look at this: http://stackoverflow.com/questions/16372678/php-why-is-this-forced-mime-download-adding-2-extra-empty-lines – Shiji.J Apr 29 '15 at 17:14
  • Thank you! I had to make an exception in code for file download, because there was some ballast around, but everythink is correct now! – Radim Kleinpeter May 05 '15 at 08:24