Consider urlencoding the url when constructing the upload?url=... path instead, which will add you more flexibility with urls like http://www.test.com/this%20is%20the%20image.jpg?with=some&additional=parameters.
So that for your example url it will be http://example.com/upload?url=http%3A%2F%2Fwww.test.com%2Fthis%2020is%2020the%2020image.jpg.
See http://php.net/urlencode for how to urlencode the variable.
Example:
Page with link
function showLink($url) {
return "/upload?url=".urlencode($url);
}
"Upload" page
echo $_GET['url']
That way, you'll still be able to process the link resulted from showLink("http://test.com/somepath?somevar=someval&somevar2=someval2") properly. Otherwise, if you won't escape it in showLink, you'll end up with the url like http://example.com/upload?url=http://test.com/somepath?somevar=someval&somevar2=someval2, and it will be quite difficult to tell whether somevar2 is the part of the request to the example.com or to the test.com (btw, $_GET['url'] will contain http://test.com/somepath?somevar=someval in such a case).