Jump to content


Photo

Spaces in URL to %20?


  • Please log in to reply
5 replies to this topic

#1 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 27 August 2006 - 08:01 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?

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 27 August 2006 - 08:05 AM

you can use:
str_replace(" ","%20",$url);

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 August 2006 - 12:14 PM

or use urlencode

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 27 August 2006 - 01:00 PM

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

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 27 August 2006 - 02:24 PM

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)

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 August 2006 - 02:30 PM

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:
<?php echo '<a href="http://domain.com/user/my file.doc">'; ?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users