I have this function in php for downloading a file, the file will be encrypted with data, and then be downloaded
Class: Connect is simply connection to database
class License extends Connect {
function __construct() {
parent::__construct();
}
public function getLicense($vars){
// file_put_contents( "/var/log/datapost/clientinfo.log", date('r'). " ". var_export($vars,true) . PHP_EOL, FILE_APPEND );
$sql = "select * from License where license_id={$vars->data->license_id}";
$res = $vars->db->query( $sql );
if($obj=$res->fetch_object()){
$filename = "License".$vars->data->license_id.".json";
// get the private key
$pk = file_get_contents("/var/www/datapost/clientinfo/keys/key1.pem");
// // private key
$res = openssl_get_privatekey($pk,"passsword");
// // encrypt it
$x=openssl_private_encrypt( json_encode($obj),$crypttext,$res);
// save the encryption
//
file_put_contents("/var/www/datapost/clientinfo/license/license{$vars->data->license_id}}.json",$crypttext);
// header('Content-Description: File Transfer');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// header('Expires: 0');
// header('Cache-Control: must-revalidate');
// header('Pragma: public');
// header('Content-Length: ' . strlen($crypttext));
echo $crypttext;
file_put_contents("/var/log/datapost/{$filename}", $crypttext, fopen("http://192.168.200.114/var/log/datapost/{$filename}", 'r' ));
flush();
file_put_contents( "/var/log/datapost/clientinfo.log", date('r'). " WOOHOO! $crypttext" . PHP_EOL, FILE_APPEND );
}
else {
file_put_contents( "/var/log/datapost/clientinfo.log", date('r'). " AAARG SHIT ".var_export($res,true) . PHP_EOL, FILE_APPEND );
}
}
}
but for some reason it is not workiing, the data is being sent in http request but no file is being downloaded with data, any help appreciated
Here is ajax request in extjs application, (on button click)
onButtonClick7: function(button, e, eOpts) {
Ext.Ajax.request({
url: 'system/index.php',
method: 'POST',
params: {
class: 'License',
method: 'getLicense',
data: Ext.encode({
license_id: Ext.getCmp('overviewGrid').selection.data.license_id
})
},
success: function( response ){
var object = Ext.decode( response.responseText, true );
//Ext.getStore('LicenseAllStore').reload();
// window.open('http://192.168.200.114/datapost/clientinfo/license/BLAH_BLAGH3.json');
},
failure: function( response ){
var object = Ext.decode( response.responseText, true );
Ext.MessageBox.alert( 'Status', object.message );
}
});
},