By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

Having trouble with spaces

P: n/a
BJB
I am trying to get my php script to display an image from a directory from
other than the webservers root directory
This doesnt work:

header('Content-Type: image/jpg');
readfile("/blah/foo bar/pic.jpg");

But this does:

header('Content-Type: image/jpg');
readfile("/blah/pic.jpg");
I am guessing it is the space that is messing it up. I tried to escape the
spaces with '\' like in Linux or %20 but they dont seem to help. I dont
want to have to change the space to something like an underscore becasue
then I'd have to change about 300 directories. Is there anyway to make this
work?

If anyone has any ideas I would greaty appreciate them.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"BJB" <bl**@spamsucks.com> wrote in message
news:l%**********************@newssvr28.news.prodi gy.com...
I am trying to get my php script to display an image from a directory from
other than the webservers root directory
This doesnt work:

header('Content-Type: image/jpg');
readfile("/blah/foo bar/pic.jpg");

But this does:

header('Content-Type: image/jpg');
readfile("/blah/pic.jpg");
I am guessing it is the space that is messing it up. I tried to escape the spaces with '\' like in Linux or %20 but they dont seem to help. I dont
want to have to change the space to something like an underscore becasue
then I'd have to change about 300 directories. Is there anyway to make this work?

If anyone has any ideas I would greaty appreciate them.


try this: header('Content-Type: image/jpg');
readfile("\"/blah/foo bar/pic.jpg\"");

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2

P: n/a
BJB wrote:
I am trying to get my php script to display an image from a directory from
other than the webservers root directory
This doesnt work:

header('Content-Type: image/jpg');
readfile("/blah/foo bar/pic.jpg"); If anyone has any ideas I would greaty appreciate them.


Works on my computer: PHP 4.3.3 on Linux

Try this:

#v+
<?php
$filename = '/blah/foo bar/pic.jpg';

if (isfile($filename) {
if (is_readable($filename) {
header('Content-Type: image/jpg');
readfile($filename);
} else exit($filename . ' is not readable.');
} else exit($filename . ' is an invalid file.');
?>
#v-

I'm betting your problem is _not_ the space :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3

P: n/a
Hmmm...are you sure "foo" and "bar" are not separated by two spaces? Or
perhaps someone is playing a joke on your and the space is actually a \xA0?
There's no reason why the code isn't working.

Uzytkownik "BJB" <bl**@spamsucks.com> napisal w wiadomosci
news:l%**********************@newssvr28.news.prodi gy.com...
I am trying to get my php script to display an image from a directory from
other than the webservers root directory
This doesnt work:

header('Content-Type: image/jpg');
readfile("/blah/foo bar/pic.jpg");

But this does:

header('Content-Type: image/jpg');
readfile("/blah/pic.jpg");
I am guessing it is the space that is messing it up. I tried to escape the spaces with '\' like in Linux or %20 but they dont seem to help. I dont
want to have to change the space to something like an underscore becasue
then I'd have to change about 300 directories. Is there anyway to make this work?

If anyone has any ideas I would greaty appreciate them.

Jul 17 '05 #4

P: n/a
On Thu, 08 Jan 2004 19:15:29 +0000, BJB wrote:
I am guessing it is the space that is messing it up. I tried to escape the
spaces with '\' like in Linux or %20 but they dont seem to help. I dont
want to have to change the space to something like an underscore becasue
then I'd have to change about 300 directories. Is there anyway to make this
work?


although spaces *shouldn't* be a problem, technically, the
reality is that they are and can be a problem. You'll be far better off
in the long run to get in the habit of not using spaces in filenames.

Trust me on that one. I promise that spaces in filenames will be a problem
if you keep using them.

A "for i in *" shell loop can change the filenames quite easily. (if you
know a small amount of shell scripting, and you should at least a little.
it's good for you.)

Or a quickie perl script will do the same.

later...

--
-------------------------
| Jeffrey Silverman |
| jeffrey-AT-jhu-DOT-edu|
-------------------------

Jul 17 '05 #5

P: n/a
BJB
> I'm betting your problem is _not_ the space :)
I think you were right. Not sure what I was doing wrong but after tinkering
with it for a little while it is working.

Thanks everyone for the help.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.