PHP SMB文件上传导致500内部服务器错误
P粉113938880
P粉113938880 2023-08-30 13:53:12
[PHP讨论组]
<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 = &quot;&quot;) { if (!empty($targetPath)) { if (substr($targetPath, -1, 1) != '/') { $targetPath .= &quot;/&quot;; } } $fileName = basename($fileToUpload); $this-&gt;srvShare-&gt;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-&gt;buildUrl($target); $targetHandle = $this-&gt;getState()-&gt;create($targetUrl); while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { $this-&gt;getState()-&gt;write($targetHandle, $data, $targetUrl); } $this-&gt;getState()-&gt;close($targetHandle, $targetUrl); return true; }</pre></p>
P粉113938880
P粉113938880

全部回复(1)
P粉882357979

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号