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:
Warning: fopen(File.xls): cannot open stream: No such file or directory
This is my upload function:
public function upload($fileToUpload, $targetPath = "") { if (!empty($targetPath)) { if (substr($targetPath, -1, 1) != '/') { $targetPath .= "/"; } } $fileName = basename($fileToUpload); $this->srvShare->put($fileToUpload, $targetPath . $fileName); }
In this case, $fileToUpload 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.
This is the put() function in smb NativeShare:
/*** 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; }
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 :)