Jump to content

Archived

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

williamh26

Temporary Download files

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

Share this post


Link to post
Share on other sites
output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6
Whatever is there created output and you cannot use header() if there has been output.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

it would help if you provided some context for the last error message. what exactly were you doing when you got that error?

Share this post


Link to post
Share on other sites

Ok, it was blank spaces on the login function... once I delete those spaces,, it works. thank you for the reply.

<?php
mysql_connect('xxxx','xxxx','xxxx');
mysql_select_db('xxxx');
?>

Share this post


Link to post
Share on other sites

When I am trying to download the file, it shows me this error..... can you guys give me a hint... thanks

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

Share this post


Link to post
Share on other sites

Does it happen every time you try to download a file? What browser?

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
header('Content-Length:'.filesize($path));
strlen instead of filesize.

Share this post


Link to post
Share on other sites

One more typo:

$path= file_get_contents('core/files/'.{$row['$file_name']});
Too many $s. Get rid of the unnecessary {}s while you're there.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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']}\"");

Share this post


Link to post
Share on other sites

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