Domanda

I have a link which shows the filename to download.When a user clicks it,it needs to get downloaded.The file gets downloaded but it contains only 0 KB.In console it shows

Resource interpreted as Document but transferred with MIME type application/force-download: "../download.php?file=filename"

My code is like this:

<a href="download.php?file=user_uploads/'.$_path['uploads'].
'logo_images/'.$row['FileName'].'" title="Click to download">'.$row['FileName'].'</a>

The download.php is like this:

<?php       
$path   =   str_replace('/download.php?file=','',$_SERVER['REQUEST_URI']);  
header("Content-Description: File Transfer");
header("Content-Type: application/force-download"); 
header("Content-Disposition: attachment; filename=\"" . basename($path . $uri[1]) . "\"" );   
@readfile($path);  
?> 

Thanks in advance.I have checked the path of the file also.

È stato utile?

Soluzione

try

<a href="yourpath_to_download.php?file=file.txt" title="Click to download">Click</a>

download.php

<?php       
$path   = 'yourpath'.$_GET['file'];  
header("Content-Description: File Transfer");
header("Content-Type: application/force-download"); 
header("Content-Disposition: attachment; filename=".$_GET['file'] );   
@readfile($path);  
?> 

file.txt - change with your file name

Altri suggerimenti

I had similar issue while downloading my file. I used this code for download.php:

<?php

$path = $_REQUEST['path'];

#setting headers
   header('Content-Description: File Transfer');
   header('Cache-Control: public');
   header('Content-Type: application/zip');
   header("Content-Transfer-Encoding: binary");
   header('Content-Disposition: attachment; filename='. basename($path));
   header('Content-Length: '.filesize($path));
   ob_clean(); #THIS!
   flush();
   readfile($path);

exit;
?>

and my link was:

<a href="file.php?path='.$encodedPath.'" name="download" class="acction" ">Download Pack</a>

Hope it helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top