Jump to content

trying to get phpxls to save a file instead of download it


richei

Recommended Posts

I've done research on this and from that I gathered that this needs to be changed to allow it to save instead of asking where to download it to.

function send($filename)
{
   header("Content-type: application/vnd.ms-excel");
   header("Content-Disposition: attachment; filename=\"$filename\"");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
   header("Pragma: public");
}

And this is what calls it: $workbook->send('HitlistSubmission_'.$subdate.'.xls'); (its not a "hitlist", its data that we have to send to iTunes to get our users promoted through iTunes).  The entire code isn't relevant.

 

I'd like to just save the file on the server because the next step in this pain the rear is to do a script to email it to iTunes.

 

From what I've read, the content-disposition is supposedly doing this, but I've commented it out and it still asks where to save it.

 

2nd question, I have this being through a website made primarily with jquery.  My function for sending the data to the page is

function export_xls() {
 var info = $("#paid").val();
 window.open('inc/export_hitlist.php?paid='+info, 'Export');
}

Ideally, i'd like to just get a confirmation message back saying all is well, but I've tried everything that I know that would do it, all I can get it to do is return the contents of the xls file.  I deleted that part of the code since i'm not using it now.

 

any help would greatly be appreciated!

Edited by richei
Link to comment
Share on other sites

the function you're calling for send is indeed setting the headers for a download, however it does not contain the file you want to save.

Usually when these headers are sent the file is already saved on your server en after setting the headers the function readfile or file_get_contents is called to complete the download request.

So, the send function is not sufficient to help you on saving the file. If you have found the filedata you want to save, try using the file_put_contents function. That's my favorite function to save files on the server.

 

Since your current function is an export it's logical to open the export in a new window. The new window will become a download.

However if you want to save the file, maybe try something like this:

var myWindow = window.open('inc/export_hitlist.php?paid='+info, 'Export');myWindow.opener.alert('File is saved');
myWindow.close();
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.