search

Home  >  Q&A  >  body text

PHP SMB file upload causes 500 Internal Server Error

<p>When I try to upload a file on a local folder to an FTP server via SMB, the file gets uploaded, but the server returns a 500 Internal Server Error with the following message: </p> <blockquote> <p>Warning: fopen(File.xls): cannot open stream: No such file or directory</p> </blockquote> <p>This is my upload function: </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>In this case, <strong>$fileToUpload</strong> is something like 'File.xls'. I've tried passing the entire path to the function but it still results in the same error. The upload is successful... the file is already on the server, but the code cannot continue as it still results in a 500 Internal Server Error. </p> <p>This is the put() function in smb NativeShare: </p> <pre class="brush:php;toolbar:false;">/*** Upload local files * * @param string $source local file * @param string $target target 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; }</pre></p>
P粉113938880P粉113938880494 days ago710

reply all(1)I'll reply

  • P粉882357979

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

    Okay..so I successfully fixed the error. The problem is that I've used this upload function elsewhere and I'm assuming I can use it again with the same parameters.. I need to change one parameter and now it works :)

    reply
    0
  • Cancelreply