我正在尝试使用php从ssh服务器下载文件。下载正在运行,但是我的函数readfile()发出警告,并且当我使用html_entity_decode()函数时,字符保持html样式。
如果我尝试使用此方法:var_dump($output)
,它会给我类似此字符串(xxx)“”的信息。包含XXX个字符但为空的字符串。
错误:
<b>Warning</b>: readfile(<?xml version="1.0" encoding="UTF-8"?><ResultatPEC xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" dateCreation="02-12-2018" versionFichier="0000842887" xsi:noNamespaceSchemaLocation="Resultats_PEC_2.10.xsd">
<IdentificationDepot CodeOffre="0" CodeSiteDepot="932930" DateDepot="26-11-2018" HeureDepot="07:04" IDDeposant="590226" NiveauService="E" NumDepot="BR099441" NumeroBip="0000793653" NumSTP="21787924" OptionDateDepot="DepotJourCreux" OptionMeca="0" OptionSiteDepot="Standard" TypeDeclaration="DEPOT" ZoneDense="1"/>
<Publication IDPCD="1174646" NoPublication="0520K87314" NoParution="391" NoParutionConstate="391" PublicationPanelisee="0" TypeParution="NUM" TypeParutionConstate="NUM">
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();
}