Author Topic: Spaces in URL to %20?  (Read 540 times)

0 Members and 1 Guest are viewing this topic.

Offline extrovertiveTopic starter

  • Enthusiast
  • Posts: 241
    • View Profile
Spaces in URL to %20?
« on: August 27, 2006, 04:01:57 AM »
I have a thing on my site where a user can upload a file to a folder. Then the url to that file will be sent to me.

However, sometimes the filename a user uploads has a space in it when sending to my email.

Ex.
http://domain.com/user/my file.doc

Thus, the url gets cut-off after the "my"

How do I make it so that if a user uploads a filename with space, it will still be a clickable link?

I tried urlencode but then I get something like http://domain.com/user/my+file.doc which is an invalid file. But http://domain.com/user/my%20file.doc works. How do I make it do that?

Offline Orio

  • Staff Alumni
  • Addict
  • *
  • Posts: 2,496
  • Gender: Male
    • View Profile
    • OriosRiddle
Re: Spaces in URL to %20?
« Reply #1 on: August 27, 2006, 04:05:17 AM »
you can use:
str_replace(" ","%20",$url);

Orio.
Think you're smarty?

(Gone until 20 to November)

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: Spaces in URL to %20?
« Reply #2 on: August 27, 2006, 08:14:53 AM »
or use urlencode

Offline onlyican

  • Devotee
  • Posts: 887
  • Gender: Male
  • British bullDog
    • View Profile
    • ClubFeet.net
Re: Spaces in URL to %20?
« Reply #3 on: August 27, 2006, 09:00:34 AM »
What I do is simular to Orio, although %20 is a whitespace

I use
str_replace(" ","_",$file_name)
before uploading
Tell me the problem, I will try tell you the solution

Offline Orio

  • Staff Alumni
  • Addict
  • *
  • Posts: 2,496
  • Gender: Male
    • View Profile
    • OriosRiddle
Re: Spaces in URL to %20?
« Reply #4 on: August 27, 2006, 10:24:56 AM »
or use urlencode
He said he use urlencode and it made the spaces to plus ("+").

Orio.
Think you're smarty?

(Gone until 20 to November)

Offline kenrbnsn

  • Guru
  • Freak!
  • *
  • Posts: 9,708
  • Gender: Male
    • View Profile
Re: Spaces in URL to %20?
« Reply #5 on: August 27, 2006, 10:30:00 AM »
If people would get into the habit of enclosing values of attributes in quotes (double or single depending on the situation), problems like this wouldn't happen. When you surround the URL in quotes, the browser will automagically do the conversion for you.

Since you didn't tell us what type of HTML tag you're trying to use, I will assume it's a "<a>" for this illustration:

In your case:
Code: [Select]
<?php echo '<a href="http://domain.com/user/my file.doc">'?>
Ken