Click to See Complete Forum and Search --> : Save a jpg image with filename different to source file


Monkey
09-04-2003, 06:26 AM
Please can someone help with this?

I'm running a web-based photographic library system on our corporate intranet and, for reasons I won't bore you with, the photo source files are stored on the server as serially numbered files, e.g. P001234.jpg.

Users are allowed to download the medium res image. Currently, they're told to right-click on the image and choose 'Save Picture As...'. The problem is, the resulting filename doesn't mean anything to either the customer or the photo library staff. Instead, each picture is traditionally referred to by its 'Picture Reference Number', e.g. 'WW654123' or HIS1234' etc., a legacy from the old manual system.

You can imagine the confusion that's caused when for instance a user downloads a picture then rings the photolibrary a few days later and refers to it by the name of say 'P001234'.

So, the question is: can JS be used as an alternative to the usual 'Save Picture As...' approach, with the additional trick of saving a graphic under a different name (which is determined by the system)?

The HTML is genererated by a CGI script on the fly so we can easily include a JS routine with the relevant source and destination filename for any given picture. As for where they save it to, it would be most useful if they can still use a browse button much like the current 'Save Picture As' method, though simply saving it to the Desktop without prompting would be just about tolerable if not.

I hope I've explained this properly, albeit v longwinded!

I'm not a JS programmer so please be gentle :) Would immensely appreciate any help, thanks.

Khalid Ali
09-04-2003, 09:05 AM
you can probably use something like this.

<script type="text/javascript">
function SaveAs(file){
if(document.execCommand){
document.execCommand("SaveAs",null,"ChangeFileName.jpg");
}
}
//-->
</script>
</head>

<body>
<img src="images/lotr3aragorn.jpg" onclick="SaveAs(this);" width="420" height="600" alt="" border="0" />


however it will only work with IE browsers,though execCommand works in NS, the SaveAs parameter does not.

Monkey
09-04-2003, 10:40 AM
Thank you for taking the trouble Khalid. I've tried your script and it brings up the 'Save HTML Document' window when I click on the image.

Whilst the newly saved file is named correctly, e.g. WW12345.jpg, it actually contains all the HTML code for the page rather than the graphic I've clicked on.

Is there any way this script could be changed so that it brings up the 'Save Picture As' window (or something as effective) instead?

Again thanks for your help with this.

Monkey
09-05-2003, 06:52 AM
Sorry to bump this back up but I'm really desperate for a solution :(

Khalid, or anyone else, is there a way to get this to save the image being clicked on rather than the page's HTML? Been searching through Google for hours and getting nowhere.

Thanks.

Khalid Ali
09-05-2003, 08:51 AM
Hi Monkey,
Here is what I could come up with.Its an actually pretty neat work around.:D

IE5.5+ only

First execCommand seems to be applied only on document,therefore you can not apply it directly on images.

1. create a hidden iframe
2.with onclick pass the obj to a function
3. in the function load the image in the iframe
4. then use settimeout to about a sec and execute the command on the iframes document

Monkey
09-05-2003, 09:51 AM
Hi again Khalid. Thanks for the latest.

Sorry to be so thick but could you please give me some example code (as you did with your first response) for that? Not being a JS coder (and only a dodgy amateur at HTML too), I don't know how to carry out the 4 steps you mention I'm afraid.

Also, will this new method still allow a different filename to be specified for the jpg that's saved?