Having trouble with spaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BJB

    Having trouble with spaces

    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.


  • CountScubula

    #2
    Re: Having trouble with spaces

    "BJB" <blah@spamsucks .com> wrote in message
    news:l%hLb.2262 0$P%1.21684313@ newssvr28.news. prodigy.com...[color=blue]
    > 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[/color]
    the[color=blue]
    > 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[/color]
    this[color=blue]
    > work?
    >
    > If anyone has any ideas I would greaty appreciate them.
    >
    >[/color]

    try this:[color=blue]
    > header('Content-Type: image/jpg');
    > readfile("\"/blah/foo bar/pic.jpg\"");[/color]


    --
    Mike Bradley
    http://www.gzentools.com -- free online php tools


    Comment

    • Pedro Graca

      #3
      Re: Having trouble with spaces

      BJB wrote:[color=blue]
      > 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");[/color]
      [color=blue]
      > If anyone has any ideas I would greaty appreciate them.[/color]

      Works on my computer: PHP 4.3.3 on Linux

      Try this:

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

      if (isfile($filena me) {
      if (is_readable($f ilename) {
      header('Content-Type: image/jpg');
      readfile($filen ame);
      } 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 =--

      Comment

      • Chung Leong

        #4
        Re: Having trouble with spaces

        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" <blah@spamsucks .com> napisal w wiadomosci
        news:l%hLb.2262 0$P%1.21684313@ newssvr28.news. prodigy.com...[color=blue]
        > 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[/color]
        the[color=blue]
        > 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[/color]
        this[color=blue]
        > work?
        >
        > If anyone has any ideas I would greaty appreciate them.
        >
        >[/color]


        Comment

        • Jeffrey Silverman

          #5
          Re: Having trouble with spaces

          On Thu, 08 Jan 2004 19:15:29 +0000, BJB wrote:
          [color=blue]
          > 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?[/color]

          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|
          -------------------------

          Comment

          • BJB

            #6
            Re: Having trouble with spaces

            > 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.


            Comment

            Working...