Reputation: 15966
I'm using the mySql INTO OUTFILE to generate a file with the sql data.
$wpdb->query("SELECT * INTO OUTFILE 'result.sql' FROM ". DB_PHOTOS .";");
I want now to get to download the file to the client side (with PHP). Since it's a WordPress Plug-in, I don't want to be location specific (like c:/result). How do I get that file with PHP and download it?
Upvotes: 0
Views: 3031
Reputation: 3827
"temp" directory allows writes on almost all hosting providers. One solution is to write to "/tmp" (Linux) or %TEMP% (Windows).
Once that is done, PHP script can stream that file to client and delete once streaming is complete.
Upvotes: 0
Reputation: 1466
Form the mysql manual:
The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some other host than the server host, you normally cannot use SELECT ... INTO OUTFILE since there is no way to write a path to the file relative to the server host's file system.
Meaning, that you can dump the file to a specific location if your php and mysql are on the same local machine, and then move the file to a better location or serve it directly bit likes of readfile()
It is true that this will not be usable if the DB and Web servers are on separate machines. Depends on what your intention is you could theoretically use mysql -e "SELECT ..." > file_name
via a system() call to generate the file locally, but it is not universal either.
Upvotes: 2