I'm getting troubles with the download from a server. If I enter to http://mypage.com can't download some .zip files. But if I enter to the page's IP, I download the files.
Other similar issue i'm having is with Godaddy, can't make my zip downloads even if I access with the IP or domain.
This is part of the code to generate the XML and ZIP it:
**xmlzip.php**
$xmlfile = $rfc.$year.$month.'BN.xml';
$xml->formatOutput = true;
$el_xml = $xml->saveXML();
$xml->save($xmlfile);
$filename = $rfc.$year.$month.'BN';
shell_exec('zip ../'.$filename.' '.$xmlfile);
try {
$date= date('Ymd_Hi');
$data = '{
"filename":"xml'.$date.'.zip",
"filename2":"'.$filename.'.zip"
}';
echo '{"success":1,"message":"ok","data":['.$data.']}';
} catch (Exception $e) {
$data = '';
echo '{"error":1,"message":"error","data":['.$data.']}';
die();
}
Then I get this on ExtJS to create the Messagebox.wait :
**downloadzip button**
msg = Ext.MessageBox.wait('Generating XML ...', '');
Ext.Ajax.request({
url: 'cakephp/app/webroot/xml.php?',
params:{
rfc: rfc,
month: month,
year: year
},
method : "POST",
headers: {
'Content-Type': 'application/json'
},
jsonData: true,
timeout: 1000000,
withCredentials: true,
success : function(response) {
var jsonResponse = JSON.parse(response.responseText);
filename = jsonResponse.data[0].filename;
filename2 = jsonResponse.data[0].filename2;
if(jsonResponse.success === 1) {
msg.hide();
Ext.getCmp("winFormXML_XMLpanel").setHtml(
'<iframe id="" name=""'+
' src="cakephp/app/webroot/download_xml.php?filename='+
filename+'&filename2='+filename2+'" width="100%" height="100%"></iframe>');
Ext.getCmp('winFormXML').destroy();
} else {
msg.hide();
Ext.Msg.alert("ERROR","Error generating XML.");
}
},
failure : function(response) {
msg.hide();
var respObj = Ext.JSON.decode(response.responseText);
console.log(respObj);
Ext.Msg.alert("ERROR", respObj.status.statusMessage);
}
});
And with this i download the generated file:
**downloadzip.php**
try {
$filename = $_REQUEST['filename'];
$filename2 = $_REQUEST['filename2'];
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$filename2);
header('Content-Length: ' . filesize($filename2));
readfile($filename2);
} catch(Exception $ex) {
echo $ex-getMessage();
}
Like i mention above, I know it works because I can download it from other computers but via IP, and not from the domain.
EDIT:
It seems that the line Ext.getCmp('winFormXML').destroy();
was giving troubles when generating. Removing that line make it works!