带有警告错误和html_entity_decode()的readfile()不起作用-PHP

时间:2019-01-29 09:09:23

标签: php character-encoding readfile

我正在尝试使用php从ssh服务器下载文件。下载正在运行,但是我的函数readfile()发出警告,并且当我使用html_entity_decode()函数时,字符保持html样式。

如果我尝试使用此方法:var_dump($output),它会给我类似此字符串(xxx)“”的信息。包含XXX个字符但为空的字符串。

错误:

<b>Warning</b>:  readfile(&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;ResultatPEC xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema- instance&quot; dateCreation=&quot;02-12-2018&quot; versionFichier=&quot;0000842887&quot; xsi:noNamespaceSchemaLocation=&quot;Resultats_PEC_2.10.xsd&quot;&gt;
&lt;IdentificationDepot CodeOffre=&quot;0&quot; CodeSiteDepot=&quot;932930&quot; DateDepot=&quot;26-11-2018&quot; HeureDepot=&quot;07:04&quot; IDDeposant=&quot;590226&quot; NiveauService=&quot;E&quot; NumDepot=&quot;BR099441&quot; NumeroBip=&quot;0000793653&quot; NumSTP=&quot;21787924&quot; OptionDateDepot=&quot;DepotJourCreux&quot; OptionMeca=&quot;0&quot; OptionSiteDepot=&quot;Standard&quot; TypeDeclaration=&quot;DEPOT&quot; ZoneDense=&quot;1&quot;/&gt;
  &lt;Publication IDPCD=&quot;1174646&quot; NoPublication=&quot;0520K87314&quot; NoParution=&quot;391&quot; NoParutionConstate=&quot;391&quot; PublicationPanelisee=&quot;0&quot; TypeParution=&quot;NUM&quot; TypeParutionConstate=&quot;NUM&quot;&gt;
     in <b>D:\www\SAGAPEC\application\modules\supervision\controllers\AdminController.php</b> on line <b>397</b><br />

我的代码:

$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');
                    if ($fileName){ 
                        $stream = ssh2_exec($connection, "cat {$fileName}");
                        stream_set_blocking($stream, true);
                        $output = stream_get_contents($stream);
                        simplexml_load_string($output); 
                        $abc = html_entity_decode($output,ENT_QUOTES,"UTF-8");

                        $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 个答案:

没有答案