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

Link to comment
Share on other sites

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 !

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.