Итак, у меня проблема с кодом.Мне нужна ваша помощь
Контекст: пользователь нажимает кнопку загрузки, в параметре http передается имя файла для загрузки и на моей странице php, в зависимости от того, существует ли файл, пользователь может загрузить его.
Пример контекста
Проблема: Независимо от того, какой файл я использую, проблема остается неизменной, в моем php я всегда передаю if, которыйчто мой файл не существует.
if (!file_exists($fileName))
Я пытался с Putty загрузить мой файл и его работу, поэтому он исходит из моего кода.Если у вас есть идея или документация, чтобы помочь мне, было бы очень полезно.
Если вы обнаружите, что мой запрос неясен, скажите мне, что я помогу вам понять
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");
});
});
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();
}