3

I know how to use download attribute to force download, but I want to do something different.

<a href="filename.mp4" download=""><img src="download.png"></a>

This is the download attribute which works properly, but I want to download using the meta tag like so:

<meta http-equiv="refresh" content="5; url=uploads/<?php echo $_POST["filename"]; ?>"> Please wait while your file start downloading.

It is working great with extensions like zipfile, rar, etc.. But when I try to use mp4, it opens up the file in a browser instead of force download.

vinS
  • 1,417
  • 5
  • 24
  • 37

1 Answers1

0

I change some thing. Sir i think it may help you: The first page code:

<?php $file = $_POST["filename"]; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="refresh" content="5; url=hello.php?file=<?php echo $file; ?>">

    <title>Document</title>
</head>
<body>

</body>
</html>

Then i create a hello.php file and it contain:

<?php
$file = 'uploads/' . $_GET['file'];

if( !file_exists($file) ) die("File not found");

header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-Length: " . filesize($file));
header('Content-type: vedio/mp4');

readfile($file);
?>

the process download the file automatic.

Jayanta
  • 146
  • 8
  • It didn't work for me. what if i wanna use that like this: AND can you please tell me why you used $_POST for filename and then $_GET method? –  Mar 29 '17 at 18:41
  • it is work for me. you just need to use **Content-Disposition: attachment;** into another file header – Jayanta Mar 29 '17 at 18:45
  • i send the file name and in hello.php file to get the filename via $_GET – Jayanta Mar 29 '17 at 18:46
  • sir can you understand – Jayanta Mar 29 '17 at 18:46
  • you just need to make a new php file. and put the header settings – Jayanta Mar 29 '17 at 18:48
  • Basically i don't want to create another php file that way user can have a direct link example.com/hello.php?file= i don't wanna give them a direct link.. i wanna make it like this example.com/ and using meta http-equiv they can't have direct link! they can only have it via console... –  Mar 29 '17 at 18:59
  • This is how im using it in begin.php https://gist.github.com/anonymous/8c1191d7da371b08695f1cb2ae782884 –  Mar 29 '17 at 19:01
  • sir try again there is no redirection as you think. try again sir please. – Jayanta Mar 29 '17 at 19:02
  • sir you don't need to use ** Please wait while your file start downloading. in the file (begin.php )** – Jayanta Mar 29 '17 at 19:04
  • this page only contain the header settings – Jayanta Mar 29 '17 at 19:04
  • you need 2 files one contain the meta data and other php file contain the header settings – Jayanta Mar 29 '17 at 19:06
  • if you don't understand please share your project sir. @NoorQureshi – Jayanta Mar 29 '17 at 19:06
  • this is my mail please send me a hi message here noorqureshics@gmail.com ill send you a project –  Mar 29 '17 at 19:16
  • are you get my mail? @NoorQureshi – Jayanta Mar 29 '17 at 19:23
  • i send the project. please tell me it is ok or not. @NoorQureshi – Jayanta Mar 29 '17 at 19:55
  • i am waiting for your ans sir. – Jayanta Mar 29 '17 at 19:57
  • one more think just put the **Dhoom.Dhaam.mp4** file into the **uploads** folder – Jayanta Mar 29 '17 at 19:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139419/discussion-between-jayanta-and-noor-qureshi). – Jayanta Mar 29 '17 at 20:21
  • There's still a problem with a downloading path: Failed to load resource: the server responded with a status of 404 (Not Found) .... it is downloading from /download.php?file=media.mp4 ... it should be /uploads/media.mp4 right? –  Mar 29 '17 at 21:21
  • hi sir, i solve the issue. i send the file via mail. please response me.@NoorQureshi – Jayanta Mar 30 '17 at 06:58
  • Your code worked in my local computer! i don't know why it didn't work on my server! My server is windows 2016 i got this error: media.mp4 might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE –  Mar 30 '17 at 10:05
  • are you get the new mail sir – Jayanta Mar 30 '17 at 10:07
  • yes i got your mail! do you think im getting this problem because im using a sub directory example.com/d/uploads is that possible that's why im getting this? i try to change this $file = 'd/uploads/' . $_GET['file']; and got file not found! –  Mar 30 '17 at 10:09
  • It worked @Jayanta i changed the memory limit for php to download larger files and it worked! –  Mar 30 '17 at 12:27
  • There's a limit issue now.. If the file is greater then 1024M it is not downloading them! I can use .htaccess showhow to force files > 1024M ? Because I have some files which are above 4GB –  Mar 30 '17 at 12:57