【问题标题】:Uploading image to web server using FTP使用 FTP 将图像上传到 Web 服务器
【发布时间】:2018-09-27 12:32:00
【问题描述】:

我对 laravel 还很陌生,目前我正忙于通过 ftp 将图像上传到 Web 服务器。我已经按照article/tutorial 进行了所有设置,但我无法让它工作,我收到了这个错误:

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

注意:当网站仍在开发中(本地主机)时,我正在将文件/图像从桌面传输到项目文件中的上传文件夹,并且一切正常,直到我决定将文件上传到 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'
    ],

感谢您的帮助!

【问题讨论】:

  • 您对网络服务器上的存储文件夹有写权限?
  • 我刚刚检查过,似乎我的权限一切正常。
  • 授予777存储文件夹权限
  • 我已经这样做了,我的权限设置为 777
  • 你现在应该避免使用 ftp,潜入ssh。也可以在 ubuntu 和文件资源管理器«连接到服务器»中的其他操作系统中使用图形化,然后拖放!还要检查 rsync!

标签: php image laravel


【解决方案1】:

你好像在用relative path

public_path()

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

【讨论】:

  • 抱歉,第一次听说绝对路径,应该如何实现呢?复制完整的目标路径而不是 public_path()?
  • 是的,例如 /var/www/your/site/public/uploads。 phpdelusions.net/articles/paths
  • 我会尝试一下。如果它有效,我会通知你
  • 我什么都试过了,我的最终路径是:$headerImage->save('/var/www/ponijeritest/ponijeri/public/uploads/'.$name);我仍然遇到同样的错误。 @SonDang
猜你喜欢
  • 2019-09-14
  • 2017-07-26
  • 2017-06-11
  • 1970-01-01
  • 2013-04-07
  • 1970-01-01
  • 2021-07-30
  • 2021-05-29
  • 1970-01-01
相关资源
最近更新 更多