我试着这样做,以便我可以下载文件,但我有一个问题,不知道如何解决它可以帮助我找到错误吗?试图这样做,你可以下载。用sftp在php
没有任何反应。并帮助我实现这个目标。我不知道如何解决这个问题,所以需要我能得到的所有帮助。
<?php
require("configuration.php");
require("include.php");
require_once('./libs/phpseclib/SFTP.php');
require_once("./libs/phpseclib/Crypt/AES.php");
if(!isset($_SESSION['clientid']))
{
//DON'T KNOW HOW THE REQEUSTOR IS!!
die();
}
$clientid = $_SESSION['clientid'];
$serverid = '';
$extendedPath = '';
$action = '';
if(!isset($_GET['serverid']) or !isset($_GET['path']) or !isset($_GET['action']))
{
die();
}
$serverid = $_GET['serverid'];
$extendedPath = $_GET['path'];
$action = $_GET['action'];
$boxDetailsSQL = sprintf("SELECT box.boxid, box.ip, box.login, box.password, box.sshport, srv.path
FROM %sbox box
JOIN %sserver srv ON box.boxid = srv.boxid
JOIN %sgroupMember grpm ON (grpm.groupids LIKE CONCAT(srv.groupid, ';%%')
OR grpm.groupids LIKE CONCAT('%%;', srv.groupid, ';%%'))
WHERE srv.serverid = %d
AND grpm.clientid = %d;", DBPREFIX, DBPREFIX, DBPREFIX, $serverid, $clientid);
$boxDetails = mysql_query($boxDetailsSQL);
$rowsBoxes = mysql_fetch_assoc($boxDetails);
$aes = new Crypt_AES();
$aes->setKeyLength(256);
$aes->setKey(CRYPT_KEY);
$sftp= new Net_SFTP($rowsBoxes['ip'], $rowsBoxes['sshport']);
if(!$sftp->login($rowsBoxes['login'], $aes->decrypt($rowsBoxes['password'])))
{
echo 'Failed to connect';
die();
}
//ACTION SELECTOR
if($action == 'list')
{
getlist($rowsBoxes, $extendedPath, $sftp);
}
if($action == 'fileUpload')
{
fileUpload($rowsBoxes, $extendedPath, $sftp);
}
if($action == 'download')
{
delete($rowsBoxes, $extendedPath, $sftp);
}
//ACTION FUNCTIONS
function download($rowsBoxes, $extendedPath, $sftp)
{
$remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
$downloadfile $sftp->put($remoteFile);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($downloadfile));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($downloadfile));
readfile($downloadfile);
}
此代码我需要帮助解决。
function download($rowsBoxes, $extendedPath, $sftp)
{
$remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
$downloadfile $sftp->put($remoteFile);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($downloadfile));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($downloadfile));
readfile($downloadfile);
}
[下面是一个例子当你继续使用'mysql_ *'函数时会发生什么。](http://stackoverflow.com/questions/26299564/php-version-upgraded-cannot-use-few-functions)了解[prepared statements](http: //en.wikipedia.org/wiki/Prepared_statement),并使用[PDO](http://us1.php.net/pdo)或[MySQLi](http://us1.php.net /库MySQLi)。 [本文](http://php.net/manual/en/mysqlinfo.api.choosing.php)将帮助你决定。 – 2014-10-16 17:44:35
试着给你的'die()'命令添加一些消息,这样你就知道它在哪停止了。另外,尝试添加'ini_set('display_errors',1); error_reporting(-1);'到你的文件的顶部让PHP显示所有错误。 – 2014-10-16 17:44:46
需要帮助下载文件文件。你用mysql是什么意思是不安全的? – 2014-10-16 17:50:28