Jump to content

Issue Writing Code for Download CSV File

Recommended Posts


I have written php code that displays to the user a list of all tenders in a database table.
The user can sort on options displayed in the dropdown box and once a filter option
is selected, the view automatically updates based on the selection.

This part is working for me.

However, I was trying to write code so that when you click the Download image on
the page, a csv file is created containing the contents of the filtered view that is
currently displayed.

This part isn't working for me and any help pointing me in the right direction would
be much appreciated.




Share this post

Link to post
Share on other sites

It looks like you're trying to use Javascript to run a PHP function, that's not how it works.  Javascript and PHP are not connected like that.  If you check your browser's error console, you'll probably see an error message that says something like CreateDownloadFile is undefined or not a function, that's because it's not a Javascript function.

One option is to create a hidden iframe on the page, and use Javascript to set the src of that iframe to a PHP file that will generate the file, and you pass whatever data you need so that PHP creates the correct file.  You can pass that data in the URL when you set the src of the iframe.  If PHP responds with the correct download headers, then the user will just see a file open/save dialog box pop up that will let them open or save the file.

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...