![]() ![]() ?file=/path/to/yourpasswordfile) and only allow downloads of certain file extensions (i.e. That way, the user can’t enter whatever file they want (i.e. Don’t just automatically read the file and send it to the user. It’s up to the user to confirm, and click save button.įor security reasons, you need to validate the file parameter the user wants to download. ![]() ![]() Binary files are not viewable on a browser, so therefore the browser doesnt know what to do with it, and a prompt for “save” will popup. The key here is the new mime type “application/octet-stream” you’re assigning to the mp3 file, which is basically saying to the browser, hey here’s a binary file. Response.ContentType = "application/octet-stream" Response.AddHeader "Content-disposition", "filename=" & strFileName (Depending on server-side language you choose, the code below may differ) but take note of the headers, and ContentType that you’ll change. Downloadfile will get the filename from the querystring url, read the contents of the file, and then send the file to the user as a stream. Then on your webpage, you name your ahref links like this: Downloadĭownloadfile above can be a php, or cshtml or asp, or whatever… as long as it can execute code on the server. If you want a left-click to download the MP3 file instead, you need to create a “file handler” on the server side. ![]() If the browser has a valid MIME type for that file extension (mp3 in this case), a left click would cause the browser’s default action for that file. If (confirm('you wanna save this image?')). Return false // Prevent default action and stop event propagation SaveImageAs1(element.nameProp, element.href) Is there a way to do this using client-side programming only? I need the browser to download the image files just as it does while clicking on an Excel sheet. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |