So here I am, I have a problem in my code. I need your help
The context: the user clicks on the download button, this passes in http parameter the name of the files to download and in my php page depending on whether the file exists, the user can download it.
The problem: No matter which file I use the problem remains the same, in my php, I always pass in the if, which is that my file does not exist.
if (!file_exists($fileName))
I tried with Putty to download my file and its working, so it comes from my code. If you have an idea or documentations to help me, it would be very appreciate.
If you find my request not clear, tell me that I help you understand
The js :
$( ".js-img-download" ).each(function(index) {
$(this).click(function(){
var currow = $(this).closest('tr');
var idevt = currow.find('td:eq(0)').text();
var nomfic = currow.find('td:eq(2)').text();
var statevt = currow.find('td:eq(3)').text();
if (idevt == '80209' && statevt == '70003'){
var filename = '//Talend/PEC_DF6/FluxSortantResultatPEC/ARCHIVES/AR/' + nomfic;
alert(filename);
}
else if (idevt == '80209' && statevt == '70002'){
var filename = '//Talend/PEC_DF6/FluxSortantResultatPEC/ARCHIVES/XML/' + nomfic;
alert(filename);
}
else if (idevt == '80205' && statevt == '70003'){
var filename = '//Talend/PEC_DF6/FluxSortantAdmissionPEC/ARCHIVES/AR/' + nomfic;
alert(filename);
}
else if (idevt == '80205' && statevt == '70002'){
var filename = '//Talend/PEC_DF6/FluxSortantAdmissionPEC/ARCHIVES/XML/' + nomfic;
alert(filename);
}
else if (idevt == '80205' && statevt == '70006'){
var filename = '//Talend/PEC_DF6/FluxSortantAdmissionPEC/ARCHIVES/XML/' + nomfic;
alert(filename);
}
else if (idevt == '80201' && statevt == '70002'){
var filename = '//Talend/PEC_DF1/PRD01_IntegrationDeclaratif/ARCHIVES/AR_TECH/' + nomfic;
alert(filename);
}
else if (idevt == '80201' && statevt == '70005'){
var filename = '//Talend/PEC_DF1/PRD01_IntegrationDeclaratif/ARCHIVES/DRP/XML/' + nomfic;
alert(filename);
}
// Ajax permettant d'envoyer le nom du fichier a télécharger au serveur
$.ajax({
type : 'POST',
url : '/supervision/admin/ajaxdownloadfile',
async : true,
data : {
filename : filename
},
success : function() {
window.location.href = '/supervision/admin/ajaxdownloadfile?name=' + filename;
}
});
});
$(this).mouseover(function(){
$(this).css("cursor","pointer");
});
});
The php :
$connection = ssh2_connect($this->_configFile->ftp->hostname, $this->_configFile->ftp->port);
if ($connection) {
$login = ssh2_auth_password($connection, $this->_configFile->ftp->login, $this->_configFile->ftp->password);
if ($login) {
$content = true;
if ($content) {
$fileName = $this->_getParam('name');
echo $fileName;
if (!file_exists($fileName)){
header('Refresh:3; url=/supervision/admin/suivifluxtechnique');
echo "ERROR 404";
echo "</br>";
echo "Le fichier n'existe pas ou à été déplacé";
}
else{
$stream = ssh2_exec($connection, 'cat'.$fileName);
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
simplexml_load_string($output);
$xml = new SimpleXMLElement($output);
$abc = htmlentities($xml->asXML());
$file = $abc;
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=" . basename($file));
readfile ($file);
exit();
}