I'm pretty new to laravel and I'm currently stuck at uploading images to web server via ftp. I've followed this article/tutorial to set everything up, but I can't get it to work, I get this error:
Can't write image data to path (/storage/ssd4/849/3099849/ponijeri/public/uploads/1523970289image1.jpg)
Note: I was transferring files/images from my desktop to uploads folder in my project files while the website was still in development (localhost), and everything was working fine until I decided to upload files to my live website on web server.
Controller code:
public function update(Request $request, $id)
{
$findObject = Accommodation::find($id);
$findObject->update($request->all());
Gallery::destroy('objects_id', $id);
foreach ($request['img'] as $img) {
$gallery = new Gallery();
$gallery->objects_id=$id;
$name = time() . $img->getClientOriginalName(); // prepend the time (integer) to the original file name
$img->move('uploads', $name); // move it to the 'uploads' directory (public/uploads)
$gallery->img=$name;
$gallery->save();
// // create instance of Intervention Image
$img = Image::make('uploads/'.$name);
$img->save(public_path().'/uploads/'.$name);
Storage::disk('ftp')->put($gallery, fopen($request->file('img[]'), 'r+'));
}
$headerImage = $request['headerImage'];
$name = time() . $headerImage->getClientOriginalName(); // prepend the time (integer) to the original file name
$headerImage->move('uploads', $name); // move it to the 'uploads' directory (public/uploads)
$findObject->headerImage=$name;
$findObject->save();
// // create instance of Intervention Image
$headerImage = Image::make('uploads/'.$name);
$headerImage->save(public_path().'/uploads/'.$name);
Storage::disk('ftp')->put($headerImage, fopen($request->file('headerImage'), 'r+'));
return redirect('/objects');
}
FTP configuration:
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'root' => '/public/uploads'
],
I appreciate any help!