0

this is an index.php

<form action="verify.php" method="post" target="_blank">
        <input name="filename" type="hidden" value="media.mp4"><p></p>
        <input name="filesize" type="hidden" value="10 MB">
        <div align="center">
            <input alt="Download" src="download.png" type="image" width="225">
        </div>
</form>

this is an verify.php

<meta http-equiv="refresh" content="5; url=download.php?file=<?php echo $file; ?>">

this is an download.php

<?php
$file = $_GET['file'];
header('Content-type: video/mp4');
header('Content-Disposition: attachment; filename="uploads/' . $file . '"');
?>

And the media files are stored in uploads directory this code need to force mp4 to download unfortunately it is not downloading from correct path.

this is the output in console: /download.php?file=media.mp4".

in order to make it work it should be /uploads/media.mp4 ... please help! tell me what im doing wrong?

wogsland
  • 9,106
  • 19
  • 57
  • 93
  • @Fred-ii- that code downloaded a file but that wasn't the original media file! that code somehow generated a new file and renamed it according to my value! with 0 bytes size... –  Mar 29 '17 at 22:07
  • I don't know why you're using a form here and a meta refresh and a header. You'll have to wait to see if someone gets what you're trying to do here. I honestly don't know why you're not just using a header (only) to force a download. – Funk Forty Niner Mar 29 '17 at 22:12
  • @Fred-ii- okay.. im using a values because i can provide my visitors a download link which will be server side, and meta refresh to make them wait for 5 sec then using header to force mp4. yeah i'll wait... thanks –  Mar 29 '17 at 22:16

2 Answers2

0

According to the PHP Documentation

// This line is where you put the name of the file the client will be receipt
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// This line is where you define which file you will send to the client
readfile('original.pdf');
  • can you please try fixing the code? i already know this documentation but how to make it work? –  Mar 29 '17 at 22:14
0

if you want the same "name" for the "output" of the file, copy this code

<?php
$file = $_GET['file'];
header('Content-type: video/mp4');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("uploads/" . $file);
?>

else :

<?php
$file = $_GET['file'];
header('Content-type: video/mp4');
header('Content-Disposition: attachment; filename="[the name the file]"');
readfile("uploads/" . $file);
?>
  • When it download after 5sec the where im uploading my media didn't work. –  Mar 29 '17 at 23:14
  • more details, please. a screenshot should be fine ;D –  Mar 29 '17 at 23:29
  • instead of url=download.php?file it should be working like this: url=domain.com this is an error while using readfile("uploads/" . $file); http://i.imgur.com/HCypw71.png –  Mar 29 '17 at 23:34
  • im calling download.php using this meta refresh –  Mar 30 '17 at 00:16
  • can you please make a screenshot of your code ?, i'm going to check this out tomorow, i'm going to sleep now, sorry. –  Mar 30 '17 at 00:19
  • can you please send me a mail with hi message i'll send you a code. noorqureshics@gmail.com –  Mar 30 '17 at 00:24