Problem for downloading a file

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Problem for downloading a file

Post by morpheus2matrix »

Hi MOD-Authors,



For my Log Actions MOD, i want to add a download logs features. So here is the code i'm using :

Code: Select all

$download = ( isset($HTTP_POST_VARS['download']) || isset($HTTP_GET_VARS['download']) ) ?  TRUE : FALSE ;

$mode = '';
if ( $download )
{
	$mode = "csv";
}

if( $mode == "csv" )
	{
		$today = date("Ymd");
		$filename = "Log_actions_" . $today . ".csv";

		@ob_start();
		@ob_implicit_flush(0);

		header('Content-Type: application/csv; name=\'' . $filename . '\'');
		header('Content-Disposition: attachment; filename=' . $filename);
		header('Content-Description: File Transfert');
		header('Pragma: no-cache');
		header('Expires: 0');

		$sql = "SELECT * 
		FROM " . LOGS_TABLE . "
		WHERE id_log IN (" . $log_list_sql . ")"; 

		if(!$result = $db->sql_query($sql)) 
		{ 
		   message_die(CRITICAL_ERROR, "Could not query log informations", "", __LINE__, __FILE__, $sql); 
		} 
		$list = $db->sql_fetchrowset($result); 
		
		$csv_output = '';
		for ($i = 0; $i < count($list); $i++) 
		{
			$csv_output .= $list[$i]['id_log'] . '; ' . ucfirst($list[$i]['mode']) . '; ' . $list[$i]['topic_id'] . '; ' . $list[$i]['username'] . '; ' . decode_ip($list[$i]['user_ip']) . '; ' . create_date($board_config['default_dateformat'], $list[$i]['time'], $board_config['board_timezone']) . '; ' . "\n";
		}

		ob_end_clean();

		printf("%s", $csv_output);
		message_die(GENERAL_MESSAGE, 'Your download will start shortly, please be patient.');
		exit;
	}

But the result of this code is the log selected appear on the screen, and they are not proposed to be downloaded.

Any ideas ? More details wanted ?


Thanks for reading that. :)
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Post by A_Jelly_Doughnut »

This behavior should be dependant on the MIME type of the file you are sending. I don't know if there is a PHP function to change the MIME type, but it should be application/plain-text for the download to run, IIRC.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

I'm trying to download a .cvs file so i've used :

Code: Select all

header('Content-Type: application/csv; name=\'' . $filename . '\'');
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

bump :)
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Mohd
Registered User
Posts: 263
Joined: Mon Jul 15, 2002 9:06 pm
Contact:

Post by Mohd »

try this :D

Code: Select all

application/force-download
Visit My Site Mohd Web Site!
My Current mod is PaFileDb Integration 0.0.8
Demo: Click Here
No support via PM
not radio
Registered User
Posts: 45
Joined: Mon Oct 20, 2003 12:34 pm

Post by not radio »

Code: Select all

header ( 'Content-Disposition: attachment; filename=' . $filename );
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

not radio wrote:

Code: Select all

header ( 'Content-Disposition: attachment; filename=' . $filename );


I've got the same result (btw, i don't see the difference with what i've written)
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Mohd
Registered User
Posts: 263
Joined: Mon Jul 15, 2002 9:06 pm
Contact:

Post by Mohd »

Mohd wrote: try this :D

Code: Select all

application/force-download
Visit My Site Mohd Web Site!
My Current mod is PaFileDb Integration 0.0.8
Demo: Click Here
No support via PM
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

Mohd wrote:
Mohd wrote:try this :D

Code: Select all

application/force-download


still same result :cry:
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Silvertongue
Registered User
Posts: 116
Joined: Tue Aug 20, 2002 4:31 am
Contact:

Post by Silvertongue »

Don't you need some type of "Refresh Content" command in the header information? I'm not all that familiar with how the auto-download stuff works, but I'm learning.

I just looked at the source code for how the mod-db starts the download automatically, and it has this line at the end:

Code: Select all

<meta http-equiv="refresh" content="5;url=http://www.phpbb.com/phpBB/uploads/mods/EasyMOD_a3_0-0-10a.zip">
So, wouldn't something like that be needed in your code, after the file has been established?
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

this is a good solution if the file already exist on the server. But i'im trying to force the download of a file which is not on it : it's created and then downloaded.
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Silvertongue
Registered User
Posts: 116
Joined: Tue Aug 20, 2002 4:31 am
Contact:

Post by Silvertongue »

Ok....but why not have the file saved on the server once you've generated it? Have an "archive" directory or something. Btw, I'm particularly interested in this because I happen to use the Log Actions mod at my forum.

I *do* think having an archive or something would be helpful...
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

Silvertongue wrote: Have an "archive" directory or something.


I agree but some werver won't allow to create files throught PHP so that's why i prefer the solution i'm trying to add :lol:
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Silvertongue
Registered User
Posts: 116
Joined: Tue Aug 20, 2002 4:31 am
Contact:

Post by Silvertongue »

I'm still doing some research on this one, 'cause now I'm interested in how it turns out. LOL I'll post some of the things that I've found that might be options...

Code: Select all

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$myfilename);
header("Expires: Mon, 25 Aug 2003 12:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
I've actually seen this in several places now.....from what I've been able to tell, try removing the

Code: Select all

name=\'' . $filename . '\'
from the content type line.
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

Silvertongue wrote: I'm still doing some research on this one, 'cause now I'm interested in how it turns out. LOL I'll post some of the things that I've found that might be options...

Code: Select all

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$myfilename);
header("Expires: Mon, 25 Aug 2003 12:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
I've actually seen this in several places now.....from what I've been able to tell, try removing the

Code: Select all

name=\'' . $filename . '\'
from the content type line.


Still same result :
Headers already sent.......


:cry:
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
Post Reply

Return to “[2.0.x] MOD Writers Discussion”