473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

What function?

My very basic code is:
<?php
$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???

Oct 19 '07 #1
12 1625
On 19 Oct, 12:07, "salonowiec" <debrza_removet...@poczta.onet.pl>
wrote:
My very basic code is:
<?php
$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.

Oct 19 '07 #2
On 19 oct, 13:07, "salonowiec" <debrza_removet...@poczta.onet.pl>
wrote:
My very basic code is:
<?php
$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.

Oct 19 '07 #3

Uzytkownik "Jean-Baptiste Nizet" <jn****@gmail.comnapisal w wiadomosci
news:11**********************@y27g2000pre.googlegr oups.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...

Oct 19 '07 #4
salonowiec wrote:
>
Uzytkownik "Jean-Baptiste Nizet" <jn****@gmail.comnapisal w wiadomosci
news:11**********************@y27g2000pre.googlegr oups.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.
js*******@attglobal.net
==================

Oct 19 '07 #5
On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
Uzytkownik "Jean-Baptiste Nizet" <jn****@gmail.comnapisal w wiadomosci
news:11**********************@y27g2000pre.googlegr oups.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.
Oct 19 '07 #6

Uzytkownik "Jerry Stuckle" <js*******@attglobal.netnapisal w wiadomosci
news:Zb******************************@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?

Oct 19 '07 #7
salonowiec wrote:
>
Uzytkownik "Jerry Stuckle" <js*******@attglobal.netnapisal w
wiadomosci news:Zb******************************@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.
js*******@attglobal.net
==================

Oct 19 '07 #8
Henri wrote:
On Fri, 19 Oct 2007 14:06:48 +0200, salonowiec wrote:
>Uzytkownik "Jean-Baptiste Nizet" <jn****@gmail.comnapisal w wiadomosci
news:11**********************@y27g2000pre.googleg roups.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.
js*******@attglobal.net
==================

Oct 19 '07 #9

"salonowiec" <de***************@poczta.onet.plwrote in message
news:ff**********@nemesis.news.tpi.pl...
My very basic code is:
<?php
$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 <no pun intended>
Oct 19 '07 #10
After hard work and many attempts I found this:

<?php
/* 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" <js*******@attglobal.netnapisal w wiadomosci
news:Nd******************************@comcast.com. ..
salonowiec wrote:
>>
Uzytkownik "Jerry Stuckle" <js*******@attglobal.netnapisal w wiadomosci
news:Zb******************************@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.
js*******@attglobal.net
==================
Oct 19 '07 #11
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" <jn****@gmail.comnapisal w
wiadomosci
news:11**********************@y27g2000pre.google groups.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?
Oct 19 '07 #12
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" <jn****@gmail.comnapisal w
wiadomosci
news:11**********************@y27g2000pre.googl egroups.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.
js*******@attglobal.net
==================

Oct 19 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
37
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture...
10
by: Brad Tilley | last post by:
Is there an easier way to do this: def print_whats_returned(function): print function print type(function)
3
by: Brett | last post by:
What is the following code doing? I see evt and event but what is the difference? <input type="radio" id="us_countryFlag1" name="us_country" onclick="togglePurDec(event)">Yes <script>...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
8
by: Viktor | last post by:
Can somebody give me an explanation what happened here (or point me to some docs)? Code: HMMM = None def w(fn): print 'fn:', id(fn) HMMM = fn
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.