php headers instant download videos -


this question has answer here:

i trying make php script when load on page downloads video. since not know headers seems can't figure out please explain why works , how header works. trying make browser download video files.can explaain headers , please.

here failing code:

<?php  //outputing video name     $file_name = $_post['filetod']; //outputting video extension e.g video/mp4     $file_ext= $_post['fileext']; //where file kept     $file_path = 'mysever.myadress.com/media/movies/' . $file_name;     header('content-type:'.$file_ext);     header('content-length:' . filesize($file_path));     header('content-description: attachment; filename='.$file_name);     readfile($file_path); ?> 

  1. if want output video, don't start outputting html , switch video data part of same file. (you can't set response headers after you've started outputting data anyway). remove before <?php , after ?>
  2. $file_url should path, on server's file system, file want make available. shouldn't url (unless want inefficient approach or need proxy different server), , if url needs start scheme (e.g. http://).
  3. the content-type needs actual content type of video (e.g. video/mp4), not file extension (and doesn't make sense provided user).

you need sanitise user data. @ present (if errors described above fixed) request file exists on server.


Comments