2

I have imported images to my own server. One of the many filenames has %20 in them, e.g. 50128%202789%20001V%20500.jpg. However the browser sees it as 50128 2789 001V 500.jpg, so it won't display the image.

What solution can I use, to display the image properly?

unor
  • 92,415
  • 26
  • 211
  • 360

1 Answers1

2

"%20" is a percent-encoding for a space, and has special meaning in a URL. Basically, you can't use spaces in a URI or URL, and have to replace them with a code to comply with the rules. Things that read URLs (the server for example) translate them back.

Unfortunately, that means if you have a filename containing this sequence, it will be mistaken for a percent-encoded space, as you're seeing.

The solution is to also percent-encode the '%'. The percent-encoding for a '%' character is "%25".

In your example, the name "50128%202789%20001V%20500.jpg" has to be encoded to "50128%25202789%2520001V%2520500.jpg" so that those '%' characters are not mistaken for spaces.

There are of course other things that get encoded. The rules are defined in the URI specification.

Community
  • 1
  • 1
Don Roby
  • 40,677
  • 6
  • 91
  • 113