首页  >  问答  >  正文

PHP SMB文件上传导致500内部服务器错误

<p>当我尝试通过SMB将本地文件夹上的文件上传到FTP服务器时,文件会被上传,但服务器返回一个500内部服务器错误,并显示以下消息:</p> <blockquote> <p>警告:fopen(File.xls):无法打开流:没有这个文件或目录</p> </blockquote> <p>这是我的上传函数:</p> <pre class="brush:php;toolbar:false;">public function upload($fileToUpload, $targetPath = "") { if (!empty($targetPath)) { if (substr($targetPath, -1, 1) != '/') { $targetPath .= "/"; } } $fileName = basename($fileToUpload); $this->srvShare->put($fileToUpload, $targetPath . $fileName); }</pre> <p>在这种情况下,<strong>$fileToUpload</strong> 是类似 'File.xls' 的内容。 我已经尝试给函数传递整个路径,但仍然导致相同的错误。 上传是成功的...文件已经在服务器上,但代码无法继续执行,因为仍然导致500内部服务器错误。</p> <p>这是smb NativeShare中的put()函数:</p> <pre class="brush:php;toolbar:false;">/*** 上传本地文件 * * @param string $source 本地文件 * @param string $target 目标文件 * @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; }</pre></p>
P粉113938880P粉113938880386 天前597

全部回复(1)我来回复

  • P粉882357979

    P粉8823579792023-08-31 09:11:58

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

    回复
    0
  • 取消回复