Hi
thompom said:
1) onclick event runs this AJAX script to increase the download counter
Got it. But still abit strange for me. Some possible ways :
[ul]
[li]Do not rely on JavaScript, count the downloads on server-side. The best is to extract the information from the web server's access log, there is mentioned the file size too.[/li]
[li]Do not break the link's default behavior. The AJAX request will be sent in the background.
Code:
[b]<a[/b] [maroon]href[/maroon][teal]=[/teal][green][i]"files/file.xxx"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"sndHit('1')"[/i][/green][b]><img[/b] [maroon]src[/maroon][teal]=[/teal][green][i]"images/dowloadicon.gif"[/i][/green] [maroon]alt[/maroon][teal]=[/teal][green][i]"Download file"[/i][/green] [maroon]border[/maroon][teal]=[/teal][green][i]"0"[/i][/green] [b]/></a>[/b]
[/li]
[li]Send the download request from the script.
Code:
[b]<a[/b] [maroon]href[/maroon][teal]=[/teal][green][i]"files/file.xxx"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"sndHit('1');return false"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"dl"[/i][/green][b]><img[/b] [maroon]src[/maroon][teal]=[/teal][green][i]"images/dowloadicon.gif"[/i][/green] [maroon]alt[/maroon][teal]=[/teal][green][i]"Download file"[/i][/green] [maroon]border[/maroon][teal]=[/teal][green][i]"0"[/i][/green] [b]/></a>[/b]
Code:
[b]function[/b] [COLOR=darkgoldenrod]handleResponseTextHIT[/color][teal]()[/teal]
[teal]{[/teal]
[b]try[/b] [teal]{[/teal]
[gray]// ...[/gray]
location[teal].[/teal]href[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'dl'[/i][/green][teal]).[/teal]href
[teal]}[/teal] [b]catch[/b][teal]([/teal]e[teal])[/teal] [teal]{[/teal] [COLOR=darkgoldenrod]alert[/color][teal]([/teal][green][i]"an error occured"[/i][/green][teal]);[/teal] [teal]}[/teal]
[teal]}[/teal]
[/li]
[/ul]
thompom said:
2) there is no mime type as it is a custom file type just for download
There still need to be something specified in the HTTP headers when the file is delivered. Usually there are some steps to set the [tt]Content-type[/tt] for a response :
[ul]
[li]specified by a server-side script[/li]
[li]added by the web server, based on the file extension[/li]
[li]added by the web server, based on the file content[/li]
[li]added by the web server, the configured default[/li]
[/ul]
Is rare and invalid if the content is still delivered without specifying anything.
Feherke.