richei Posted January 22, 2014 Share Posted January 22, 2014 (edited) 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 January 22, 2014 by richei Quote Link to comment Share on other sites More sharing options...
Mace Posted January 22, 2014 Share Posted January 22, 2014 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(); Quote Link to comment Share on other sites More sharing options...
richei Posted January 22, 2014 Author Share Posted January 22, 2014 So instead of using those headers, I just need to write the information to a file like I normally would? I'll give it a try. Quote Link to comment Share on other sites More sharing options...
richei Posted January 22, 2014 Author Share Posted January 22, 2014 dang forums and its edit times. Turns out that what I thought exported the file contents doesn't do that, it just sends the filename, not the contents. I tried file_put_contents and that just saved the filename in the file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.