Jump to content

Spaces in URL to %20?


extrovertive

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?
Link to comment
https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/
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
Link to comment
https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81108
Share on other sites

Archived

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

×
×
  • Create New...

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.