Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change save option to download file? #449

Open
theavuthnhel opened this issue Dec 19, 2014 · 3 comments
Open

How to change save option to download file? #449

theavuthnhel opened this issue Dec 19, 2014 · 3 comments

Comments

@theavuthnhel
Copy link

theavuthnhel commented Dec 19, 2014

Hello!

I am every interested with this package, but I couldn't modify save option to download file. It is still work as save file.

Any one help me plase?

Thanks in Advance...


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@martindavis
Copy link

Hello theavuthnhel,

This is an issue that is really independent of the library. But believe me when I say I understand your frustration in trying to accomplish this. The easiest way to do this is to save the document to a temporary file; open it; and send it to the browser.

Please note; you'll need a separate PHP file that does nothing more than just send the file!

Save the following as Sample_02_TabStops_File.php in the samples folder after you run Example 2.

<?php

// Get FileName from CMS/Framework/Library or temporary variable:
$newDoc = 'results/Sample_02_TabStops.docx';

/* Add our HTTP Headers */
// http:https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// http:https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html

// Doc generated on the fly, may change so do not cache it; mark as public or
// private to be cached.
header('Pragma: no-cache');
// Mark file as already expired for cache; mark with RFC 1123 Date Format up to
// 1 year ahead for caching (ex. Thu, 01 Dec 1994 16:00:00 GMT)
header('Expires: 0');
// Forces cache to re-validate with server
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// DocX Content Type
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
// Tells browser we are sending file
header('Content-Disposition: attachment; filename=Sample_02_TabStops.docx;');
// Tell proxies and gateways method of file transfer
header('Content-Transfer-Encoding: binary');
// Indicates the size to receiving browser
header('Content-Length: '.filesize($newDoc));

// Send the file:
readfile($newDoc);

// Delete the file if you so choose. BE CAREFULE; YOU MAY NEED TO DO THIS
// THROUGH YOUR FRAMEWORK:
//unlink($newDoc);

// End the session. BE CAREFUL; YOU NEED TO DO THIS THROUGH YOUR FRAMEWORK:
session_write_close();
?>

Hope that helps!

@milosodalovic
Copy link

Very good @martindavis! Thanks!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants