What function?
am 19.10.2007 13:07:07 von salonowiec
My very basic code is:
$fname='alpha.ext';
readfile($fname);
?>
Only when ext is txt I'm getting a reasonable content, otherwise there's a
lot of bush. What function should I use to open doc, xls, pdf, gif?...
Can you help to a supernewbie???
Re: What function?
am 19.10.2007 13:22:16 von Captain Paralytic
On 19 Oct, 12:07, "salonowiec"
wrote:
> My very basic code is:
>
> $fname='alpha.ext';
> readfile($fname);
> ?>
> Only when ext is txt I'm getting a reasonable content, otherwise there's a
> lot of bush. What function should I use to open doc, xls, pdf, gif?...
> Can you help to a supernewbie???
This has nothing to do with the extension. It is the contents of the
files.
If you renamed alpha.ext to alpha.doc, the output would still be the
same.
In general, a .doc file will be written by Microsoft Word in its
custom format, similarly for all the other files.
A .gif file is a binary representation of an image. If you send the
correct headers, then the results of the readfile with a .gif file
would be an image on your browser.
Re: What function?
am 19.10.2007 13:42:41 von jnizet
On 19 oct, 13:07, "salonowiec"
wrote:
> My very basic code is:
>
> $fname='alpha.ext';
> readfile($fname);
> ?>
> Only when ext is txt I'm getting a reasonable content, otherwise there's a
> lot of bush. What function should I use to open doc, xls, pdf, gif?...
> Can you help to a supernewbie???
If what you want to do is sending a gif, jpeg, pdf file or whatever
file to the browser and the browser displays it as it would if you had
clicked on a direct link to the file, then you must send the mime type
of the file in the HTTP response:
header("Content-Type: image/gif");
for a gif file, for example.
With direct links, the web server does it automatically, but if you
want to do it in PHP, you have to do it yourself. Read the user
comments on http://www.php.net/readfile to see some examples.
JB.
Re: What function?
am 19.10.2007 14:06:48 von salonowiec
Uzytkownik "Jean-Baptiste Nizet" napisal w wiadomosci
news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
> If what you want to do is sending a gif, jpeg, pdf file or whatever
> file to the browser and the browser displays it as it would if you had
> clicked on a direct link to the file, then you must send the mime type
> of the file in the HTTP response:
>
> header("Content-Type: image/gif");
>
> for a gif file, for example.
>
> With direct links, the web server does it automatically, but if you
> want to do it in PHP, you have to do it yourself. Read the user
> comments on http://www.php.net/readfile to see some examples.
>
> JB.
>
It's working good with this header function, it displays O. K. There is
another question (I'm probably stubborn): the address line shows something
like http://www.xxx/vvv/alpha.pdf. And this is my problem - can I "force"
system (server, browser?) to keep showing http://......something.php ? The
true reason for this is, that in my PHP script I put the code that redirects
unlogged user to somewhere. But when you remember once only the address
http://......./alpha.pdf you will reach it any time without logging. Sorry,
I'm not sure if it's clear enough...
Re: What function?
am 19.10.2007 14:29:28 von Jerry Stuckle
salonowiec wrote:
>
> Uzytkownik "Jean-Baptiste Nizet" napisal w wiadomosci
> news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
>
>> If what you want to do is sending a gif, jpeg, pdf file or whatever
>> file to the browser and the browser displays it as it would if you had
>> clicked on a direct link to the file, then you must send the mime type
>> of the file in the HTTP response:
>>
>> header("Content-Type: image/gif");
>>
>> for a gif file, for example.
>>
>> With direct links, the web server does it automatically, but if you
>> want to do it in PHP, you have to do it yourself. Read the user
>> comments on http://www.php.net/readfile to see some examples.
>>
>> JB.
>>
> It's working good with this header function, it displays O. K. There is
> another question (I'm probably stubborn): the address line shows
> something like http://www.xxx/vvv/alpha.pdf. And this is my problem -
> can I "force" system (server, browser?) to keep showing
> http://......something.php ? The true reason for this is, that in my PHP
> script I put the code that redirects unlogged user to somewhere. But
> when you remember once only the address http://......./alpha.pdf you
> will reach it any time without logging. Sorry, I'm not sure if it's
> clear enough...
>
It is doing exactly what you asked. Use used the header() function to
redirect to a different page. The browser requested the new page and
displayed its url. If you redirect, that's how it works.
And even if the browser didn't display the URL your files would not be
secure. Security by obfustication is worse than no security - at least
with no security, you know you're insecure.
If you want to protect them from being downloaded, you need to either
use HTTP authentication or deliver the files in your script (with the
appropriate headers).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: What function?
am 19.10.2007 14:37:56 von henri
On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
> Uzytkownik "Jean-Baptiste Nizet" napisal w wiadomosci
> news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
>
>> If what you want to do is sending a gif, jpeg, pdf file or whatever
>> file to the browser and the browser displays it as it would if you had
>> clicked on a direct link to the file, then you must send the mime type
>> of the file in the HTTP response:
>>
>> header("Content-Type: image/gif");
>>
>> for a gif file, for example.
>>
>> With direct links, the web server does it automatically, but if you
>> want to do it in PHP, you have to do it yourself. Read the user
>> comments on http://www.php.net/readfile to see some examples.
>>
>> JB.
>>
> It's working good with this header function, it displays O. K. There is
> another question (I'm probably stubborn): the address line shows
> something like http://www.xxx/vvv/alpha.pdf. And this is my problem -
> can I "force" system (server, browser?) to keep showing
> http://......something.php ? The true reason for this is, that in my PHP
> script I put the code that redirects unlogged user to somewhere. But
> when you remember once only the address http://......./alpha.pdf you
> will reach it any time without logging. Sorry, I'm not sure if it's
> clear enough...
you can use sessions to check if the user is authorized (eg logged in or whatever) to view the content.
Just to this check before actually displaying any content.
Re: What function?
am 19.10.2007 14:39:38 von salonowiec
Uzytkownik "Jerry Stuckle" napisal w wiadomosci
news:Zb-dnQ0AD6ulPoXanZ2dnUVZ_vShnZ2d@comcast.com...
> If you want to protect them from being downloaded, you need to either use
> HTTP authentication
....this I'd like to avoid...
>or deliver the files in your script (with the appropriate headers).
>
Could you, please, give a sample of such a hader?
Re: What function?
am 19.10.2007 14:55:09 von Jerry Stuckle
salonowiec wrote:
>
> Uzytkownik "Jerry Stuckle" napisal w
> wiadomosci news:Zb-dnQ0AD6ulPoXanZ2dnUVZ_vShnZ2d@comcast.com...
>> If you want to protect them from being downloaded, you need to either
>> use HTTP authentication
>
> ...this I'd like to avoid...
>
>> or deliver the files in your script (with the appropriate headers).
>>
> Could you, please, give a sample of such a hader?
>
RTFM.
http://us2.php.net/manual/en/function.header.php
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: What function?
am 19.10.2007 14:55:56 von Jerry Stuckle
Henri wrote:
> On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
>
>> Uzytkownik "Jean-Baptiste Nizet" napisal w wiadomosci
>> news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
>>
>>> If what you want to do is sending a gif, jpeg, pdf file or whatever
>>> file to the browser and the browser displays it as it would if you had
>>> clicked on a direct link to the file, then you must send the mime type
>>> of the file in the HTTP response:
>>>
>>> header("Content-Type: image/gif");
>>>
>>> for a gif file, for example.
>>>
>>> With direct links, the web server does it automatically, but if you
>>> want to do it in PHP, you have to do it yourself. Read the user
>>> comments on http://www.php.net/readfile to see some examples.
>>>
>>> JB.
>>>
>> It's working good with this header function, it displays O. K. There is
>> another question (I'm probably stubborn): the address line shows
>> something like http://www.xxx/vvv/alpha.pdf. And this is my problem -
>> can I "force" system (server, browser?) to keep showing
>> http://......something.php ? The true reason for this is, that in my PHP
>> script I put the code that redirects unlogged user to somewhere. But
>> when you remember once only the address http://......./alpha.pdf you
>> will reach it any time without logging. Sorry, I'm not sure if it's
>> clear enough...
>
> you can use sessions to check if the user is authorized (eg logged in or whatever) to view the content.
> Just to this check before actually displaying any content.
>
Not if the user is directly accessing a non-php file, i.e. a pdf.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: What function?
am 19.10.2007 15:04:43 von Steve
"salonowiec" wrote in message
news:ffa3ev$g1m$1@nemesis.news.tpi.pl...
> My very basic code is:
>
> $fname='alpha.ext';
> readfile($fname);
> ?>
> Only when ext is txt I'm getting a reasonable content, otherwise there's a
> lot of bush. What function should I use to open doc, xls, pdf, gif?...
> Can you help to a supernewbie???
hell, if read file gets me bush, i'm all over it!
thanks for the tip
Re: What function?
am 19.10.2007 23:11:00 von salonowiec
After hard work and many attempts I found this:
/* logging test coming at this line */
header("Content-Type: application/pdf");
$fname='not1.pdf';
readfile($fname);
?>
This is quite enough for me, the address keeps being ........./*.php so for
unlogged user the site will not be accessible.
Many thanks...
Uzytkownik "Jerry Stuckle" napisal w wiadomosci
news:NdudnTsk4tCnNIXanZ2dnUVZ_r7inZ2d@comcast.com...
> salonowiec wrote:
>>
>> Uzytkownik "Jerry Stuckle" napisal w wiadomosci
>> news:Zb-dnQ0AD6ulPoXanZ2dnUVZ_vShnZ2d@comcast.com...
>>> If you want to protect them from being downloaded, you need to either
>>> use HTTP authentication
>>
>> ...this I'd like to avoid...
>>
>>> or deliver the files in your script (with the appropriate headers).
>>>
>> Could you, please, give a sample of such a hader?
>>
>
> RTFM.
>
> http://us2.php.net/manual/en/function.header.php
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>
Re: What function?
am 19.10.2007 23:56:19 von henri
On Fri, 19 Oct 2007 08:55:56 -0400, Jerry Stuckle wrote:
> Henri wrote:
>> On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
>>
>>> Uzytkownik "Jean-Baptiste Nizet" napisal w
>>> wiadomosci
>>> news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
>>>
>>>> If what you want to do is sending a gif, jpeg, pdf file or whatever
>>>> file to the browser and the browser displays it as it would if you
>>>> had clicked on a direct link to the file, then you must send the mime
>>>> type of the file in the HTTP response:
>>>>
>>>> header("Content-Type: image/gif");
>>>>
>>>> for a gif file, for example.
>>>>
>>>> With direct links, the web server does it automatically, but if you
>>>> want to do it in PHP, you have to do it yourself. Read the user
>>>> comments on http://www.php.net/readfile to see some examples.
>>>>
>>>> JB.
>>>>
>>> It's working good with this header function, it displays O. K. There
>>> is another question (I'm probably stubborn): the address line shows
>>> something like http://www.xxx/vvv/alpha.pdf. And this is my problem -
>>> can I "force" system (server, browser?) to keep showing
>>> http://......something.php ? The true reason for this is, that in my
>>> PHP script I put the code that redirects unlogged user to somewhere.
>>> But when you remember once only the address http://......./alpha.pdf
>>> you will reach it any time without logging. Sorry, I'm not sure if
>>> it's clear enough...
>>
>> you can use sessions to check if the user is authorized (eg logged in
>> or whatever) to view the content. Just to this check before actually
>> displaying any content.
>>
>>
> Not if the user is directly accessing a non-php file, i.e. a pdf.
well, then what about an htaccess?
Re: What function?
am 20.10.2007 00:17:56 von Jerry Stuckle
Henri wrote:
> On Fri, 19 Oct 2007 08:55:56 -0400, Jerry Stuckle wrote:
>
>> Henri wrote:
>>> On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
>>>
>>>> Uzytkownik "Jean-Baptiste Nizet" napisal w
>>>> wiadomosci
>>>> news:1192794161.771509.304950@y27g2000pre.googlegroups.com.. .
>>>>
>>>>> If what you want to do is sending a gif, jpeg, pdf file or whatever
>>>>> file to the browser and the browser displays it as it would if you
>>>>> had clicked on a direct link to the file, then you must send the mime
>>>>> type of the file in the HTTP response:
>>>>>
>>>>> header("Content-Type: image/gif");
>>>>>
>>>>> for a gif file, for example.
>>>>>
>>>>> With direct links, the web server does it automatically, but if you
>>>>> want to do it in PHP, you have to do it yourself. Read the user
>>>>> comments on http://www.php.net/readfile to see some examples.
>>>>>
>>>>> JB.
>>>>>
>>>> It's working good with this header function, it displays O. K. There
>>>> is another question (I'm probably stubborn): the address line shows
>>>> something like http://www.xxx/vvv/alpha.pdf. And this is my problem -
>>>> can I "force" system (server, browser?) to keep showing
>>>> http://......something.php ? The true reason for this is, that in my
>>>> PHP script I put the code that redirects unlogged user to somewhere.
>>>> But when you remember once only the address http://......./alpha.pdf
>>>> you will reach it any time without logging. Sorry, I'm not sure if
>>>> it's clear enough...
>>> you can use sessions to check if the user is authorized (eg logged in
>>> or whatever) to view the content. Just to this check before actually
>>> displaying any content.
>>>
>>>
>> Not if the user is directly accessing a non-php file, i.e. a pdf.
>
> well, then what about an htaccess?
>
For authentication it still uses HTTP authentication.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================