doumin1897 2018-04-17 13:44
浏览 86

使用FTP将图像上载到Web服务器

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!

  • 写回答

1条回答 默认 最新

  • doukaojie8573 2018-04-17 14:53
    关注

    It seems you are using relative path

    public_path()

    on production server, please try to use absolute path instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败