PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
It may be more of a problem in how you are using the filename. Could you post the code where the filename is inserted into a tag? Basically, what I'm getting at is if you don't use quotes around your attribute values, this sort of thing can and will happen. However, your server may prefer to get all requests encoded, in which case, rawurlencode() and urlencode() can be used.
You should ALWAYS wrap your attribute values in quotes. Not only is it required for standards compliance, but it also makes the code easier to read (IMO), and of course stops problems like this from happening.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
My advice is to use preg_replace because depending on the OS you may need to alter the rules of special chars that need replacement and you may use something like: