【发布时间】:2019-06-09 13:54:22
【问题描述】:
我不明白问题出在哪里。如果有人有想法:(我必须从 ssh 服务器下载文件,但文件会根据用户的要求进行切换。我有一个用于 ssh 连接和下载的 PHP 文件。我正在使用 ajax,因为我有发送文件位置。
让我们看看代码:
HTML:
<?php if ( !is_null($this->listdepotdrpadmin) ) { ?>
<table id="supervisionResDepotDrp">
<thead>
<tr>
<th class="center">EVT_ID</th>
<th class="center">EVT_DT</th>
<th class="center">EVT_NOMFIC</th>
<th class="center">EVT_STATUT</th>
<th class="center">EVT_TEXTE</th>
<th class="center">DOWNLOAD</th>
</tr>
</thead>
<tbody>
<tr>
<!-- Le 7ème champ statut_depot n'est pas affiché, car il sert uniquement pour les RG
Il est redondantt avec le 6ème qui est sa traduction en langage humain -->
<?php foreach ($this->listdepotdrpadmin as $elem) :?>
<tr>
<td class="center"><?php print_r($elem['evt_id'])?></td>
<td class="center"><?php print_r($elem['evt_dt'])?></td>
<td id="afficher" class="center"><?php print_r($elem['evt_nomfic'])?></td>
<td class="center"><?php print_r($elem['evt_statut'])?></td>
<td class="center"><?php print_r($elem['evt_texte'])?></td>
<!-- Si le champs evt_statut est remplis, affiche l'icone de telechargement -->
<td class="center">
<?php if (isset($elem['evt_nomfic'])) : ?>
<img class='img-download' src='/img/download.png' id="js-download-file">
<?php endif;?>
</td>
</tr>
<span id="spnText"></span>
<?php endforeach; ?>
</tr>
</tbody>
</table>
<?php } ?>
PHP 文件:
public function ajaxdownloadfileAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->view->lib = $this->_labelsFile;
$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('fileName');
$local = ' C:\Users\nboulein\Desktop\test\ ';
ssh2_scp_recv($connection,$fileName,$local);
}
$connection = null; unset($connection);
}
}
$result['status'] = 'OK';
$result['message'] = 'LE ficheir a bien ete telecharger';
echo json_encode($result);
}
Ajax 文件:
// Gestion du bouton de téléchargement du fichier
$('#resultatsRecherche').on('click','#js-download-file',function(){
$('#js-download-file').css("cursor","pointer" );
var currow = $(this).closest('tr');
var fileName = currow.find('td:eq(2)').text();
alert(fileName);
$.ajax({
type : 'POST',
url : '/supervision/admin/ajaxdownloadfile',
async : true,
data : {
fileName : fileName
},
success : function(result) {
var vResult = jQuery.parseJSON(result);
if(vResult.status == 'OK'){
alert(vResult.message);
}
}
});
});
在我的网页上什么都没有发生,当我打开控制台时,会出现这样的情况:
未捕获的类型错误:$(...).on 不是 HTMLDocument 中的函数。
(admin.js:224) 在 Object.resolveWith (jquery-1.5.1.min.js:16)
在 Function.ready (jquery-1.5.1.min.js:16) 在 HTMLDocument.A (jquery-1.5.1.min.js:16)
我尝试进入我的 AJAX 网页,结果如下:
警告:ssh2_scp_recv() [function.ssh2-scp-recv]:无法接收远程文件
D:\www\SAGAPEC\application\modules\supervision\controllers\AdminController.php
在第 383 行 {"status":"OK","message":"LE ficheir a bien ete telecharger"}
【问题讨论】:
-
“不起作用”是没有描述的。 How to Ask你观察到了什么?服务器和浏览器的错误日志。
标签: php ajax ssh html-table