Jump to content

Temporary Download files


williamh26

Recommended Posts

Hi Guys I trying to download files and I have this error message, hopelly you guys can help me please

Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 18

 

 

This is the code I use to force the download

<?php
include('core/inc/init.inc.php');
   if(isset($_GET['file_id'])) {  
     $file_id=(int)$_GET['file_id'];    
     $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id");    
     if(mysql_num_rows($file)!=1){   
       echo'Invalid file Id';
     }else{
       $row=mysql_fetch_assoc($file);
       if ($row['file_expiry']<time()){
          echo'This file has expired'; 
       }else{
              $path="core/files/{$row['$file_name']}";
              header('Content-Type:application/octet-stream');
              header('Content-Description:File Transfer');
              header('Content-Transfer-Encoding:binary');
              header("Content-Disposition:attachment;filename=\"{$row['file_name']}\"");
              header('Content-Length:'.filesize($path));
              readfile($path);
       }
     }
}
?>

Thank you for your help.....

Link to comment
https://forums.phpfreaks.com/topic/292021-temporary-download-files/
Share on other sites

Thank you.... fixed... but now this is the error I have

 

C:\Users\folder1\AppData\Local\Temp\AADMn2IX.jpg.part could not be saved, because the source file could not be read.

Try again later, or contact the server administrator.

 

 

The image failed to saved and download it.

 

thank you

<?php
include('core/inc/init.inc.php');
   if(isset($_GET['file_id'])) {  
     $file_id=(int)$_GET['file_id'];    
     $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id");    
     if(mysql_num_rows($file)!=1){   
       echo'Invalid file Id';
     }else{
       $row=mysql_fetch_assoc($file);
       if ($row['file_expiry']<time()){
          echo'This file has expired'; 
       }else{
              $path= file_get_contents('core/files/'.{$row['$file_name']});
              header("Content-Disposition:attachment;filename=\"{$row['file_name']}\"");
              header('Content-type: application/force-download');
              header('Content-Length:'.filesize($path));
              header('Content-type: application/octetstream');
              echo $path;
       }
     }
}
?>

Test this!

thank you very much it works....

<?php
include('core/inc/init.inc.php');
   if(isset($_GET['file_id'])) {  
     $file_id=(int)$_GET['file_id'];    
     $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id");    
     if(mysql_num_rows($file)!=1){   
       echo'Invalid file Id';
     }else{
       $row=mysql_fetch_assoc($file);
       if ($row['file_expiry']<time()){
           
          echo'This file has expired'; 
       }else{
           
              $path= file_get_contents('core/files/'.$row['file_name']); 
              header("Content-Disposition:attachment;filename=\"$row{['file_name']}\"");
              header('Content-type: application/force-download');
              header('Content-Length:'.strlen($path));
              header('Content-type: application/octetstream');
              echo $path;
       }
     }
}
?>

I   will continue with this project....thnak you

header("Content-Disposition:attachment;filename=\"$row{['file_name']}\"");
The variable there is a bit off. The {}s should be around the whole thing, like

header("Content-Disposition:attachment;filename=\"{$row['file_name']}\"");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.