My PHP script is outputting the contents of a .sql file, after it has been called by a POST request from my Delphi Desktop Client.
Here is what is happening:
mysqldump
and generates a file - xdb_backup.sql
include "xdb_backup.sql";
which will print and return it to the Desktop Client, whereafter it deletes the SQL file.The problem is, that the size of the SQL file can vary (for testing, I generated one that is 6 mb). I would like my desktop client to be able to show the progress, however the PHP script does not expose it's size, so I have no Progressbar.Max
value to assign.
How can I make my PHP script let the Client know how big it is before the whole thing is over
?
Note: Downloading the SQL file is not an option, as the script has to destroy it. :)
You would do
$fsize = filesize($file_path);
where $file_path will be path to the generated file xdb_backup.sql,
to get the filesize in server and return headers with the following line attached.
header("Content-Length: " . $fsize);
Take a look at http://www.hotscripts.com/forums/php/47774-download-script-not-sending-file-size-header-corrupt-files-since-using-remote-file-server.html which explains a download php script.
You have to send a Content-Length header using header
function. Something like this:
header('Content-Length: '.filesize('yourfile.sql'));
You may want to send the file using readfile
instead of include.
You can set the Content-Length header with the size of xdb_backup.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With