Php Can';t写入图像数据laravel 5干预

Php Can';t写入图像数据laravel 5干预,php,image,laravel-5,intervention,Php,Image,Laravel 5,Intervention,这个问题在SO中被问了很多次,但我仍然不明白为什么这对我不起作用 我正在从事电子商务的Laravel项目 问题是,当管理员上载产品的图像文件时,会出现以下错误: 无法将图像数据写入路径 () 以下是存储图像和相关条目的控制器代码段: public function storeGeneral(Request $request) { $this->validate($request, [ 'code' => 'required|alpha_

这个问题在SO中被问了很多次,但我仍然不明白为什么这对我不起作用

我正在从事电子商务的Laravel项目

问题是,当管理员上载产品的图像文件时,会出现以下错误:

无法将图像数据写入路径 ()

以下是存储图像和相关条目的控制器代码段:

public function storeGeneral(Request $request)
{

    $this->validate($request, [
    'code'                => 'required|alpha_dash|unique:products',
    'name'                => 'required',
    'description'         => 'string',
    'details'             => 'string',
    'price'               => 'required|regex:/^\d*(\.\d{2})?$/',
    'tax_amount'          => 'required|regex:/^\d*(\.\d{2})?$/',
    'net_price'           => 'required|regex:/^\d*(\.\d{2})?$/',
    'weight'              => 'required|integer',
    'image_file'          => 'image|mimes:jpeg,jpg,JPG'
    ]);
    if ($request->ajax() ) {
        if ($request->file('image_file' ) ) {
            $request['img_code'] = 'img-' . $request->get('code' );
            $product = Product::create($request->all() );
            $product->categories()->attach($request->input('category_id') );

            Session::put('product_last_inserted_id', $product->id);

            $mgCode = DB::table('products')->latest()->limit(1)->pluck('img_code');
            $imageType = [
                'product' => [
                    'height' => 350,
                    'width' => 350
                ],
                'carousel' => [
                    'height' => 163,
                    'width' => 163
                ],
                'cart' => [
                    'height' => 64,
                    'width' => 64
                ]
            ];

            foreach($imageType as $key => $value)
            {
                $fileName = Safeurl::make($mgCode );
                $image = Image::make($request->file('image_file' ) );
                //$path = public_path( 'images/uploads/products/' );
                $path = url('/images/uploads/products/');

                if ($key == 'product') {
                    $image->resize($value['width'], $value['height'] );
                    $image->save($path.'/'.$fileName."-". $value['width'] ."-".$value['height'] .".jpg", 100 );
                } else if ($key == 'carousel' ) {
                    $image->resize($value['width'], $value['height'] );
                    $image->save($path.'/'.$fileName."-". $value['width'] ."-".$value['height'] .".jpg", 100 );
                } else if ($key == 'cart' ) {
                    $image->resize($value['width'], $value['height'] );
                    $image->save($path.'/'.$fileName."-". $value['width'] ."-".$value['height'] .".jpg", 100 );
                }
            }
        } else {
            $product = Product::create($request->all() );
            Session::put('product_last_inserted_id', $product->id);
        }
        return response(['status' => 'success', 'msg' => 'The product has been added successfully.']);
    }
    return response(['status' => 'failed', 'msg' => 'The product could not be added successfully.']);
}
我对
images
目录及其子目录的文件夹权限是
0777

但是我仍然得到了上面提到的错误异常

编辑1:

这是我的托管帐户文件管理器中的文件夹结构,位于
public\u html
目录中:

有人能帮我解决这个问题吗


提前感谢。

您正在尝试使用
url
保存
图像。不要使用
url
尝试以下操作

$path = base_path().'/images/uploads/products';

您正试图使用
url
保存
image
。不要使用
url
尝试以下操作

$path = base_path().'/images/uploads/products';

我不知怎么搞明白了

我没有使用
url()
base\u path()
,而是使用了
public\u path()

我使用的代码:

$path = public_path('../../public_html/ankur/images/uploads/products');

工作很有魅力。

我不知怎么搞明白了

我没有使用
url()
base\u path()
,而是使用了
public\u path()

我使用的代码:

$path = public_path('../../public_html/ankur/images/uploads/products');

工作起来很有魅力。

您无法使用http路径保存图像。您必须使用base_path()或手动键入完整服务器目录路径/home/webtuningtechnology/public_html/images/这样

您无法使用http路径保存图像。您必须使用base_path()或手动键入完整服务器目录路径/home/webtuningtechnology/public_html/images/如下所示

您是否已经创建了此路径/图片/上传/产品/是。。我已经创建了目录。您是否已经创建了此路径/图片/上传/产品/是。。我已经创建了directory.Nope。出现以下错误:
无法将图像数据写入路径(/home/benefitho/ankur laravel/images/uploads/products//img-newprod-540-150420-350-350.jpg)
能否尝试删除“products”前面的正斜杠?否。出现以下错误:
无法将图像数据写入路径(/home/benefitho/ankur laravel/images/uploads/products//img-newprod-540-150420-350-350.jpg)
能否尝试从“产品”前面删除正斜杠`