Jump to content

Problem with dowloading page


kid304

Recommended Posts

I have a very small segment code below :

      
            header('Pragma: public');
      		header('Expires: 0');
      		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      		header('Content-Type: $content_type');
      		header("Content-Disposition: attachment; filename=\"$name\";\n\n");
      		header('Content-Length: ' . filesize($link));
      		readfile($link);

 

$link is the real path to my file.

when I test that file without "include" command, it work fine.

but when I add "include" command, the file I download from server can't open (too many strange characters...). 

Could you provide me  another way to solve my problem.?

 

(All I need : 1 simple script which allow download "printable documents" and this script allow me add "include" command )

 

PS: I use include command to import a class help me query data more easily !

 

Link to comment
https://forums.phpfreaks.com/topic/184889-problem-with-dowloading-page/
Share on other sites

Hi guy, I just extract a piece of code, if I add include like this:

include("mysql_class.php");

When I download file, That file will be wrong. (You can't understand content of that documents)

 

i don't understand contents of this post to be honest.

 

there's obviously something wrong with mysql_class.php that's causing your script to fail.  but since i won't understand the contents of your extreme script, i guess i can't be of any help to you.

Sorry, You will understand what I want to ask right now:

The first page:  page1.php:

<?
echo "hello word";
?>

And the second:  page2.php:

<?			
		ob_start();
		include("page1.php");

		$link="ShellProgramming.doc";
		$name='example.doc';
		$content_type='application/msword';
		header('Pragma: public');
      		header('Expires: 0');
      		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      		header('Content-Type: $content_type');
      		header("Content-Disposition: attachment; filename=\"$name\";\n\n");
      		header('Content-Length: ' . filesize($link));
      		readfile($link);

?>

 

Explain: I have a document named: ShellProgramming.doc

I write script above to download that document. but when I download that document, I can't read it.

 

if I throw away: ob_start();

include("page1.php");

it will work fine.

 

(ob_start()  avoid "header error" only )

 

Help me solve problem ! Thanks so much !

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.