Link to home
Start Free TrialLog in
Avatar of lword
lword

asked on

Open a Save/Download dialog using javascript

hi all,
iam doing a mail interface using PHP .
i just want to popup the save/download dialog box on clicking the attachments in the inbox and save it to the local disk.

Please help me out.

Thanks in advance

Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi lword,


You can't directly. You have to provide a download. When you click the link, you need to use PHP's header() function to send at least 2 headers.

1 - header('Content-type: xxx');
2 - header('Content-length: yyy');

xxx is the type of file being downloaded. If you don't want the browser to process it (either itself or by a plugin) you need to provide a type which is raw data. Maybe application/octet-stream.

yyy is the length of the data being sent. This is useful to show the user how long they have left to download.

Then you would use ...

readfile(zzz);

where zzz is the name of the file.




Regards,

Richard Quadling.
Avatar of lword
lword

ASKER

Thanks Richard Quadling.

is it possible to do it in client-side i.e using Javascript / vbscript.?

i want the user to download the attachment
which is stored in the web server ,(and displayed in the inbox as attachments) to their
local hard disk by invoking the  open/save download dialog box.

Thanks
lword
You say "inbox". Can you explain what you mean by this?

Avatar of lword

ASKER

hi  RQuadling

i'm developing a mail interface like gmail,yahoo etc.
Inbox is the place in which all the incoming mails , from the mail server , are displayed.
the incoming  mails from the mailserver is downloaded to the database and shown as inbox in the browser.
If the incoming mails received contains attachments, Iam storing it in the web server and displaying the file name
as attachment in the inbox.I want the user to download the attachments to the client (local hard disk by prompting the open/save disalog box ), by clicking on the attachment link in the inbox.
 
thanks
lword
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial