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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.