Jump to content

Archived

This topic is now archived and is closed to further replies.

extrovertive

Spaces in URL to %20?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
you can use:
str_replace(" ","%20",$url);

Orio.

Share this post


Link to post
Share on other sites
What I do is simular to Orio, although %20 is a whitespace

I use
str_replace(" ","_",$file_name)
before uploading

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=105792.msg422754#msg422754 date=1156680893]
or use [url=http://php.net/urlencode]urlencode[/url]
[/quote]
He said he use urlencode and it made the spaces to plus ("+").

Orio.

Share this post


Link to post
Share on other sites
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]<?php echo '<a href="http://domain.com/user/my file.doc">'; ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.