繁体   English   中英

PHP SMB 文件上传成功但返回 500 Internal Server Error

[英]PHP SMB File upload is successful but returns 500 Internal Server Error

当我尝试通过 SMB 将文件从 PC 上的本地文件夹上传到 ftp 服务器时,文件已上传,但服务器返回 500 内部服务器错误并显示以下消息:

警告:fopen(File.xls):无法打开 stream:没有这样的文件或目录

这是我上传的function:

public function upload($fileToUpload, $targetPath = "") {
    if (!empty($targetPath)) {
        if (substr($targetPath, -1, 1) != '/') {
            $targetPath .= "/";
        }
    }

    $fileName = basename($fileToUpload);
    $this->srvShare->put($fileToUpload, $targetPath . $fileName);
}

$fileToUpload在这种情况下类似于“File.xls”。 我已经尝试为 function 提供整个路径。 但它仍然会导致相同的错误。 上传确实有效。文件在服务器上,但代码无法继续,因为它仍然导致 500 内部服务器错误。

这是来自 smb NativeShare 的 put() function:

/**
 * Upload a local file
 *
 * @param string $source local file
 * @param string $target remove file
 * @return bool
 *
 * @throws \Icewind\SMB\Exception\NotFoundException
 * @throws \Icewind\SMB\Exception\InvalidTypeException
 */
public function put($source, $target) {
    $sourceHandle = fopen($source, 'rb');
    $targetUrl = $this->buildUrl($target);
    $targetHandle = $this->getState()->create($targetUrl);
    while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) {
        $this->getState()->write($targetHandle, $data, $targetUrl);
    }
    $this->getState()->close($targetHandle, $targetUrl);
    return true;
}

好吧..所以我能够修复错误。 问题是我已经在某个地方使用了这个上传 function,我假设我可以用相同的参数再次使用它。我需要更改参数,现在它可以工作了:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM