Page 1 of 1

Download File

Posted: Sat Jun 17, 2006 5:29 am
by my_raj_raj2
Hi all,

I am devlop the ticket concept project.I create upload attachement option in add new ticket.

I am store the attachement files in the database.(datatype longblob).

When show the ticket there is a option for download attachements.

When I download the notepad files it is show the content.

The other format not download properly.

Download file coding is

Code: Select all

<?
  
  $post_id=$_GET['id'];
 
      $sql=mysql_query("select * from posts_text where post_id=$post_id");
      $row=mysql_fetch_array($sql);
      $content = $row['content']; 
  
 	@ob_end_clean();
	# Make sure that IE can download the attachments under https.
	header( 'Pragma: public' );
	header( 'Expires: 0' );
	header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header( 'Cache-Control: private',false);
	header( 'Content-Type: ' . $row['filetype'] );
                header( 'Content-Length: ' .$row['filesize'] );

	# Added Quotes (") around file name.
	header( 'Content-Disposition: attachment; filename="' . $row['filename'] . '"' );
	header( 'Content-Description: Download Data' );
	header( 'Pragma: no-cache' );
	header( 'Content-Transfer-Encoding: binary' );

 	readfile( $content );
 
?>



The download word file show content

<br />
<b>Warning</b>: readfile(ÐÏ à¡± á): failed to open stream: Invalid argument in
<b>download.php</b> on line <b>33</b><br />



Anybody know what is the error?

Thanking you.

Posted: Sat Jun 17, 2006 8:06 am
by printf
readfile is to read a IO handle, just dump the data using echo!

Code: Select all

<? 
  
  $post_id=$_GET['id']; 
  
      $sql=mysql_query("select * from posts_text where post_id=$post_id"); 
      $row=mysql_fetch_array($sql); 
  
        @ob_end_clean(); 
        # Make sure that IE can download the attachments under https. 
        header( 'Pragma: public' ); 
        header( 'Expires: 0' ); 
        header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
        header( 'Cache-Control: private',false); 
        header( 'Content-Type: ' . $row['filetype'] ); 
                header( 'Content-Length: ' .$row['filesize'] ); 

        # Added Quotes (") around file name. 
        header( 'Content-Disposition: attachment; filename="' . $row['filename'] . '"' ); 
        header( 'Content-Description: Download Data' ); 
        header( 'Pragma: no-cache' ); 
        header( 'Content-Transfer-Encoding: binary' ); 

        echo $row['content']; 
  
?>

Download File

Posted: Mon Jun 19, 2006 7:39 am
by my_raj_raj2
Hi,

Thank u very much. It works fine.

I change echo instead of readfile.

Can u explain me
readfile is to read a IO handle
Thank u.