dongzhan8001 2019-01-28 13:43 采纳率: 0%
浏览 68

Js / Php - 我无法用ssh打开一个文件

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.

Exemple of context

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&apos;existe pas ou &agrave; &eacute;t&eacute; d&eacute;plac&eacute;";
                    }
                    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(); 
                    } 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line