Php Help - urgent

Discussion in 'PHP' started by fakhruddin, Sep 16, 2006.

  1. #1
    i am running an image hosting script

    when i upload normal images everything is fine


    but when i upload images with spaces in between it creates problems

    for eg - If i upload "Abc Vbg.jpg"

    The Link Comes Like This
    http://localhost/photo/Abc+Vbg.jpg
    Code (markup):
    But the correct link to the image is
    http://localhost/photo/Abc Vbg.jpg
    Code (markup):
    how do i solve this issue
     
    fakhruddin, Sep 16, 2006 IP
  2. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    Noting wrong in the link. It is urlencoded with space encoded to + sign.

    So if you create url for the image Abc Vbg.jpg, it is encoded to Abc+Vbg.jpg
     
    harsh789, Sep 16, 2006 IP
  3. fakhruddin

    fakhruddin Peon

    Messages:
    193
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    neways probs solved now

    thanks neways
     
    fakhruddin, Sep 16, 2006 IP
  4. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you should always filter file names.
    if somebody uses filenames with weird characters in them, you might not be able to remove them from your server.

    use preg_replace to filter the filenames
     
    discoverclips, Sep 16, 2006 IP
  5. intoex

    intoex Peon

    Messages:
    414
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    generate new filename - replace spaces with _ and add some unique value - this will solve the problem
     
    intoex, Sep 17, 2006 IP
  6. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What filter rule do you need to prevent that from happening?
     
    Icheb, Sep 17, 2006 IP
  7. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    function cleanfile($file) {
    return preg_replace('/[^0-9A-Za-z\- ]/', "", $file);
    }
    PHP:
    that should work :)
     
    discoverclips, Sep 17, 2006 IP
  8. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Awesome, thank you!
     
    Icheb, Sep 17, 2006 IP