[使用PHP通过SFTP上传图片正在上传0字节文件

问题描述 投票:-1回答:1

我正在尝试使用PHP和HTML表单将图像上传到远程SFTP服务器以获取文件。该文件已成功上传,但是当我检查目录时,该文件有0个字节(或只有1个字节)。

我已经检查了php.ini的“ upload_max_filesize”,可以了。我已经尝试了很多代码,但是还是一样。这是代码的一部分:

    include('remote_conexion.php'); //this file already has the include SFTP.php and the connection

    $foto = ($_FILES['avatar']['name']);
// Upload file
$sftp->put('/home/user/images/avatars/',$foto, NET_SFTP_LOCAL_FILE);

以下是屏幕快照,其中文件已上传到服务器。仅1个字节,我不知道该怎么办。https://prnt.sc/pj9ng1

php html sftp phpseclib
1个回答
1
投票

从PHP Docs

$_FILES['userfile']['name']
//The original name of the file on the client machine.

$_FILES['userfile']['tmp_name']
//The temporary filename of the file in which the uploaded file was stored on the 
server.

只需将“名称”更改为“ tmp_name”,但在此之后或之前,您必须rename该文件,因为临时文件名很丑陋

© www.soinside.com 2019 - 2024. All rights reserved.