471,354 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Having trouble with spaces

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
5 4099
"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
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
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
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
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.

Similar topics

3 posts views Thread by Ian Arnold | last post: by
11 posts views Thread by 2D Rick | last post: by
5 posts views Thread by Mike Labosh | last post: by
1 post views Thread by tshad | last post: by
2 posts views Thread by shweta khare | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.