通过 phpseclib 上传的文件减少到 14 个字节?

File uploaded via phpseclib gets reduced to 14 bytes?

我最近为我的服务器配置了 phpseclib 2.0;所以我对此很陌生。当尝试通过普通 HTML 表单和 PHP 使用 phpseclib 上传文件小于 1 MB 的 jpg 图像时,图像准确上传到我想要的位置,但是文件大小为只有 14 个字节(970 KB 是原始文件大小)。有什么帮助吗?我的代码如下:

// Establish the SFTP connection
$sftp = new \phpseclib\Net\SFTP('www.myhost.com');

// Login with username and password, and inform if the login was successful
if (!$sftp->login('myuser','mypassword')) {
  $uploadAnswer = 'SFTP Connection failed!';
  } else {
  $uploadAnswer = 'SFTP Connection succesful!';
  // migrate to root folder
  $rootPath = $sftp->pwd();
  // Create destination Path
  $destinationPath = $rootPath.'/myfolder/'.$_FILES['myupload']['name'];

  // Load the file onto the server, and inform if upload was successful
  if (!$sftp->put($destinationPath,$_FILES['myupload']['tmp_name'])) {
    $uploadAnswer = "There's been a problem with the Upload!";
    } else {
    $uploadAnswer = 'File successfully uploaded!';
    }
  }

当我 运行 这样做时,消息 'File successfully uploaded!' 也会正确显示。这里发生了什么??

替换行

$sftp->put($destinationPath,$_FILES['myupload']['tmp_name'])

$sftp->put($destinationPath,$_FILES['myupload']['tmp_name'],SFTP::SOURCE_LOCAL_FILE)

所推荐的link提供的没有正常工作。解决方案是:

$sftp->put($destinationPath,$_FILES['myupload']['tmp_name'],\phpseclib\Net\SFTP::SOURCE_LOCAL_FILE)

这完成了工作;所以问题是 SFTP class 可能由于某种原因无法正确识别。如果有人已经遇到同样的问题;请告诉我。