[PHP] New Line Character while downloading a file!

2004-09-24 Thread Divick Kishore
Hi,
I am a newbie to php so pls be gentle.

I am having problems while downloading a file via this script. I am sending
the following headers and then a call to readfile function in the swcript.
This leads to opening of a download popup but the file name being shown is
the name of the script file rather than of the file which I am forcing the
user to download. Another problem is that when the file is downloaded a new
line character is added to the top of it unncessarily due to which it can't
be opened with any image viewer.
Once I reomove that newline character, it works fine.


Script.php

//some validations go here.

$relative_file =
"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).
"/../Dir/".$fileName;
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename=' . $relative_file);
@readfile($relative_file);

Thanks in Advance,
Kishore Divick.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] New Line Character while downloading a file!

2004-09-24 Thread Divick Kishore
Thanks for pointing that out. But still it doesn't solve my problem.

Thanks for a prompt response.


"Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Divick Kishore wrote:
> > Hi,
> > I am a newbie to php so pls be gentle.
> >
> > I am having problems while downloading a file via this script. I am
sending
> > the following headers and then a call to readfile function in the
swcript.
> > This leads to opening of a download popup but the file name being shown
is
> > the name of the script file rather than of the file which I am forcing
the
> > user to download. Another problem is that when the file is downloaded a
new
> > line character is added to the top of it unncessarily due to which it
can't
> > be opened with any image viewer.
> > Once I reomove that newline character, it works fine.
> >
> >
> > Script.php
> >
> > //some validations go here.
> >
> > $relative_file =
> > "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).
> > "/../Dir/".$fileName;
>
> Why are you reading the file through http when it's on the same server?
Try
>
> $relative_file = "../Dir/".$fileName;
>
>
> > header('Content-type: image/jpeg');
> > header('Content-Disposition: attachment; filename=' . $relative_file);
>
> $relative_file contains "http:// . and so on". You should use
$fileName
>
> > @readfile($relative_file);
> >
> > Thanks in Advance,
> > Kishore Divick.
> >

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] New Line Character while downloading a file!

2004-09-24 Thread Divick Kishore
Indeed you figured it right. I do have a new line at the top of the
 wrote in message
news:[EMAIL PROTECTED]
> On Fri, 24 Sep 2004 16:15:19 +0530, Divick Kishore
> <[EMAIL PROTECTED]> wrote:
> >Another problem is that when the file is downloaded a new
> >line character is added to the top of it unncessarily due to which it
can't
> >be opened with any image viewer.
> >Once I reomove that newline character, it works fine.
>
> Maybe that's the key to the problem. You may have a blank line
> somewhere. Something like:
>
> 
>
> 
> code...
>
> ?>
>
> The blank line before the " headers are sent.
> Does the code have this?
>
> HTH
>
>
> 
>
> ramil
>
> http://ramil.sagum.net

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] New Line Character while downloading a file!

2004-09-24 Thread Divick Kishore
I  have
 header('Content-Disposition: attachment; filename=' . $fileName);



> Do you have
>
> header('Content-Disposition: attachment; filename=' . $relative_file);
>
> or
>
> header('Content-Disposition: attachment; filename=' . $fileName);
>
> ?


"Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Divick Kishore wrote:
> > Indeed you figured it right. I do have a new line at the top of the
> >  > newline is not being appended. But the problem of file name is still
there.
> > The download popup asks for the file name as DownloadScript.php which
> > contains the code below.
> >
>
> Do you have
>
> header('Content-Disposition: attachment; filename=' . $relative_file);
>
> or
>
> header('Content-Disposition: attachment; filename=' . $fileName);
>
> ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] New Line Character while downloading a file!

2004-09-24 Thread Divick Kishore
Sorry what I have is  header('Content-Disposition: attachment; filename=' .
$relative_file); And changing that to fileName solved my problem perfectly.

Thanks a lot once again.

Divick Kishore

"Divick Kishore" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I  have
>  header('Content-Disposition: attachment; filename=' . $fileName);
>
>
>
> > Do you have
> >
> > header('Content-Disposition: attachment; filename=' . $relative_file);
> >
> > or
> >
> > header('Content-Disposition: attachment; filename=' . $fileName);
> >
> > ?
>
>
> "Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Divick Kishore wrote:
> > > Indeed you figured it right. I do have a new line at the top of
the
> > >  > > newline is not being appended. But the problem of file name is still
> there.
> > > The download popup asks for the file name as DownloadScript.php which
> > > contains the code below.
> > >
> >
> > Do you have
> >
> > header('Content-Disposition: attachment; filename=' . $relative_file);
> >
> > or
> >
> > header('Content-Disposition: attachment; filename=' . $fileName);
> >
> > ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php