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

时间:2018-04-17 13:44:55

标签: php image laravel

我对laravel很陌生,我目前只是通过ftp将图像上传到网络服务器。我已按照此article/tutorial设置了所有内容,但我无法让它工作,我收到此错误:

  

无法将图像数据写入路径(/storage/ssd4/849/3099849/ponijeri/public/uploads/1523970289image1.jpg)

注意:我正在将文件/图像从我的桌面传输到我的项目文件中的上传文件夹,而网站仍在开发中(localhost),一切正常,直到我决定将文件上传到我在web服务器上的实时网站。

控制器代码:

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配置:

'ftp' => [
        'driver' => 'ftp',
        'host' => env('FTP_HOST'),
        'username' => env('FTP_USERNAME'),
        'password' => env('FTP_PASSWORD'),
        'root' => '/public/uploads'
    ],

我感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您似乎正在使用relative path

  

public_path()

在生产服务器上,请尝试改为使用absolute path