Q:

Default filename of image dragged from the browser window

In Safari, when I drag an image from the browser window to the desktop the image take its filename from the last part of the URL. For example:
http://www.mysite.com/images/05

the image name is
05.jpeg

Is this a behaviour consistent across all (recent IE8+) browsers?
Can I decide an arbitrary filename the image will get when dragged out of the browser?
I tried (in Safari) to set the name and alt tag of the image but this doesn't have any effect.
Maybe can I decide the filename setting it in the header of the server response when the image is served?

A:

One method is to specify the desired filename in the header of the response when the file is served.
I'm on php so...
header('Content-disposition: inline; filename=the-image.jpg');

When the image is dragged from the browser window to the desktop the file name is the-image.jpg
Unfortunately this is not consistent across all browsers, in particular Firefox doesn't follow the rule and sticks to the last part of the URL for giving the name.
The solution that works across all browsers is to avoid specifying the name in the header of the response and set the name as the last part of the URL.
As I can manage the routes for my website the solution I adopted is to let the route to images end with a string that is ignored by the server and has the sole purpose of defining a filename for the image in case it's dragged out of the browser.
For example:
http://www.my-site.com/images/05/my%20custom%20filename.jpg

What tells the server what image the client wants is the parameter following images, so 05 in the example.
It's important to note that the filename must be URI-component encoded, escaping spaces, slashes, percents, and so on...
The filename, to be OS friendly, should then be scrubbed from slashes, back-slashes and other characters that may eventually create mess.

