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
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

Link to comment
Share on other sites

<?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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.