duck__boy Posted April 22, 2010 Share Posted April 22, 2010 Hey all, I have a function that allows users to export data from a table to a .csv file. This was pretty simple and works ok, but I have two problems that I don't know how to solve. First, how would I fire this script with a button, and second how (when the button is first pressed) do I bring up a box to allow the user to select where to save the file? I realise the second query is more related to client side as opposed to server, so I'm really just after pointer of what to look for on that one. Any help would be appriciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/ Share on other sites More sharing options...
ignace Posted April 22, 2010 Share Posted April 22, 2010 First, how would I fire this script with a button <form action="#" method="POST"> <?php if (isset($_POST['some_button'])) { echo 'fired'; } ?> <input type="submit" name="some_button" value="Click me!"> </form do I bring up a box to allow the user to select where to save the file? http://webdesign.about.com/od/php/ht/force_download.htm Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046292 Share on other sites More sharing options...
duck__boy Posted April 22, 2010 Author Share Posted April 22, 2010 Hey ignace, thanks for the reply. I have now got my functions firing off of a button press, so thanks for that. I'm still suffering from a lack of understanding about the other part though - First thing I do when the button is pressed is run a script that creates a temporary file on my server, and that works fine. Next I'm trying to use the help you provided to force the download of that data, and I have created a new file and placed the headers with correct names etc in the there, but when that file is called I get to following error - Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\intranet dev\wp-content\themes\assets\index_users.php:41) in C:\wamp\www\intranet dev\wp-content\themes\assets\functions\download_tempData-csv.php on line 2 index_users.php is where I'm trying to control this from, and download_tempData-csv.php is where I placed the headers (and nothing else, just the headers.). I'd very much appriciate it if you were able to help further. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046302 Share on other sites More sharing options...
ignace Posted April 22, 2010 Share Posted April 22, 2010 Move it to the top of your script Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046383 Share on other sites More sharing options...
duck__boy Posted April 22, 2010 Author Share Posted April 22, 2010 I can't put it at the top of the main script as the file won't yet exist, thats why I put it in another file on it's own, but for some reason that is not being picked up. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046431 Share on other sites More sharing options...
ignace Posted April 22, 2010 Share Posted April 22, 2010 Then include it at the top of your future scripts. You get that error because their is output whether it be a space or HTML Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046477 Share on other sites More sharing options...
duck__boy Posted April 23, 2010 Author Share Posted April 23, 2010 Well delete any white space and the file is now being picked up, but using the code below the file that is saved contains the complete source of the page, rather than the file I wish to down load. Sorry to be a pain, I really have no experience of this at all though. Thanks. <?php header('Content-type: text/plain'); header('Content-disposition: attachment; filename=c:\\tempData.csv'); readfile('c:\\tempData.csv'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199360-run-a-function-on-button-press/#findComment-1046906 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.