我想使用phpseclib库将文件上传到sftp服务器。下面是我写PHPSECLIB调用未定义的函数crypt_random_string()
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.5');
$fileName = "sImg3.jpeg";
$fileData = file_get_contents($fileName);
$b64Data = base64_encode($fileData);
// upload the file to ftp server
include('Net/SFTP.php');
include_once('include/config.php'); // contains sftp connection details
$sftp = new Net_SFTP($ftpHost);
if (!$sftp->login($ftpUser, $ftpPasswd))
{
die("Failed to connect to SFTP server");
}
else
{
$sftp->put($filename,$b64Data);
echo "Uploaded the file (".$filename.")\n";
}
当我尝试运行此代码,我得到“PHP致命错误:调用到/var/www/phpseclib0.3.5/Net/SSH2未定义功能crypt_random_string()第1014行的.php“。
我已经安装了php5-mcrypt和phpseclib。我是否需要为phpseclib安装任何其他依赖项?请告诉我。
感谢很多提前, 问候, Sudheer
感谢您的回复。是的,我查了你上面提到的代码。这就是我得到的错误!它的'函数未定义'错误,而不是'文件未找到'错误。真的很困惑,为什么我看到函数未定义的错误。 – user591912
如果你在net/SSH2.php的'require_once'之前加一个'echo'到目前为止x1
\ r \ n“'这个x2
\ r \ n”'之后? – neubert
试过了。增加了这个回声“this far x1
\ r \ n”; (!function_exists('crypt_random_string')){ echo“this far x2
\ r \ n”; require_once('Crypt/Random。PHP'); echo“this far x3
\ r \ n”; } 而且,这里是我“这么远X1输出
这么远X2
这一步X3
PHP致命错误:调用到/var/www/phpseclib0.3.5/Net/SSH2未定义功能crypt_random_string() .php on line 1017“ – user591912