PHP Classes

What is the best PHP download file with dialog class?: Create a file on the server and save it to my computer

Recommend this page to a friend!
  All requests RSS feed  >  What is the best PHP download file wi...  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

What is the best PHP download file with dialog class?

A request is featured when there is no good recommended package on the site when it is posted. Edit

Picture of Georges Jaroslaw by Georges Jaroslaw - 9 years ago (2015-01-06)

Create a file on the server and save it to my computer

This request is clear and relevant.
This request is not clear or is not relevant.

+1

I want to create a file using AJAX requests to PHP on the server side.

Then I need to download the file to the computer with dialog box to change title location.

The file is data from MySQL to be exported in CSV format.

  • 1 Clarification request
  • 1. Picture of Manuel Lemos by Manuel Lemos - 9 years ago (2015-01-19) Reply

    Downloading files and prompt the user choose the download location on your computer is easy. Just serve the file with the appropriate content-type header set to application/octet-stream which is the generate MIME type for binary data.

    However, if you want to request the file via AJAX, that is tricky because there is another approach, the download prompt dialog only appears when serving a file via its own browser request.

    Maybe you can create an hidden iframe in the page and make the file be served inside that iframe. That would avoid redirecting the current browser window to another URL. But I don't know a class that does that.

    • 2. Picture of Justin Eldracher by Justin Eldracher - 8 years ago (2015-06-22) in reply to comment 1 by Manuel Lemos Comment

      What I do is copy the file I want to download to a specific directory (with PHP of course...) that has a .htaccess file with the following contents: <FilesMatch "\.(?i:csv)$">

        ForceType application/octet-stream
        Header set Content-Disposition attachment
      

      </FilesMatch> You could then use javascript and do a window.location = 'downloads/' + filename; once the AJAX call is finished, and that would bring up the save as dialog.

      Hope that helps.

    • 3. Picture of Manuel Lemos by Manuel Lemos - 8 years ago (2015-06-22) in reply to comment 2 by Justin Eldracher Comment

      That would have the same problem. Either you redirect to the file URL or make it load inside an iframe.

Ask clarification

Recommend package
: 
: