Can't be done.
There is no concept of downloading something from the browser to the phone. It doesn't make any sense in the iPhone system.
The iPhone is a closed system. Every application (including the browser) runs in it's own sandbox. Each sandbox includes it's own application specific file system and no application has access to the files of any other application.
Assuming your code works on Safari on a Mac, the download would end up in the users ~/Download folder. Then you'd go to some other application on your Mac, access that folder and do something with what you downloaded (whatever it was, picture, data, etc.)
On an iPhone, even if you downloaded something, via Safari, it would end up in the Safari sandbox which would be completely useless. So they don't bother with supporting it on the iPhone.
There is a special way to download images to the users photo album (which is accessible in a limited fashion by any app) from Safari -- but that's something a user does:
http://www.tuaw.com/2008/07/17/iphone-101-saving-images-in-safari/[
^]
You can write a native Objective-C app that can download from a website to the users photo album. But you can't do it from a browser based app.