Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    echoing GET variable strips "%20" from string

    Hi

    I am trying to echo a get variable simply to get an image submitted via a form (cant use POST for other reasons) dislayed on the following page. SImply like this...

    <img src="images/<?php echo $_GET['image']; ?>"

    Problem is that if the image uploaded has a name such as:

    "my%20image%20upload.jpg" (i.e. it has %20 instead of white space)

    The the GET echo strips out the %20's to give me html code like:

    <img src="my image upload">

    ...and ebcause the image is saved on the server as my%20image%20upload.jpg it therefore wont display

    Anybody got any advice how to get around this?

    Thanks

    Glynster

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Do a string replace
    PHP Code:
    <?php echo str_replace(' ','%20',$_GET['image']); ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    or, for a more complete solution (works for more than just spaces)

    urldecode($_GET['image']);

    HTH
    Dan
    Last edited by whizard; 08-15-2007 at 12:05 AM. Reason: forgot about the inline code feature
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Hmm forgot about that function. Dan's suggestion is the better solution.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •