Mysql 使用干预/图像与Laravel API进行上载/调整大小

Mysql 使用干预/图像与Laravel API进行上载/调整大小,mysql,laravel,intervention,Mysql,Laravel,Intervention,我正在尝试使用公开创建的路径(即uploads/images)将图像上载到数据库,但不幸的是,它没有显示任何错误,并且图像没有上载或保存到目录 控制器 名称空间App\Http\Controllers; 使用\Http\Request; 使用App\Image; 类ImagesController扩展控制器 { 公共功能指数 { 返回视图“图像”; } 公共函数uploadRequest$request { $this->validate$请求[ 'images'=>'必需| image | m

我正在尝试使用公开创建的路径(即uploads/images)将图像上载到数据库,但不幸的是,它没有显示任何错误,并且图像没有上载或保存到目录

控制器

名称空间App\Http\Controllers; 使用\Http\Request; 使用App\Image; 类ImagesController扩展控制器 { 公共功能指数 { 返回视图“图像”; } 公共函数uploadRequest$request { $this->validate$请求[ 'images'=>'必需| image | mimes:jpeg、png、jpg、gif、svg | max:2048', ]; $image=$request->file'images'; $input['imagename']=time..$image->getClientOriginalExtension; $destinationPath=public_path'/uploads/images'; $img=Image::make$Image->getRealPath; $img->resize100100,函数$constraint{ $constraint->aspectRatio; }->保存$destinationPath.'/.$input['imagename']; $destinationPath=public_path'/images'; $image->move$destinationPath,$input['imagename']; $this->positmage->add$input; if!空$input['imagename']{ 返回响应->json[ “成功”=>正确, “数据”=>$input['imagename']->toArray ]; } 返回true; } } 路线

路线::发布“上传”和“上传”ImagesController@upload'; 模型

名称空间应用程序; 使用Illumb\Database\Elount\Model; 类图像扩展模型 { 受保护的$fillable=['image']; }
在将图像文件保存到目录之前,请确保已在标记中添加了enctype=multipart/form数据

检查您是否更改了位于C:\xampp\htdocs\isp\config\filesystems.php的文件系统的公共路径。 现在检查我下面的代码,以获得想法,并根据此修改您的代码

    public function site(Request $request)
   {  


        if ($request->hasFile('imagename')) {
            $image = $request->file('imagename');
            $filename = 'image'.rand(1,5) . '.' . $image->getClientOriginalExtension();
            $location = public_path('uploads/image/' . $filename);
            Image::make($image)->save($location);
        }
        Session::flash('flash_message_success', 'Site profile updated successfully');
        return redirect()->route('site');


   }
我想你已经给了一个额外的/公开的路径函数。纠正它。并更改您的验证参数“images”=>“required | image | mimes:jpeg、png、jpg、gif、svg、jpeg、png、jpg、gif、svg | max:2048”


希望任何一个条件都被满足,你就会成功

尝试采用这种方式,然后运行

php artisan storage:link 
另外,将控制器更改为此

public function upload(Request $request)
    {

        $img = new Image();

        $validation = $request->validate([
            'title' => 'string',
            'image' => 'required|file|image|mimes:jpeg,png,gif,webp|max:2048'
        ]);
        $file      = $validation['image']; // get the validated file
        $extension = $file->getClientOriginalExtension();
        $filename  = 'mm-image-' . time() . '.' . $extension;
        $path      = $file->storeAs('/uploads/images', $filename);
        $img->image = $request->image;
        $img->title = $path;

        dd($img);


            if (!empty($img)){
                return response()([
                    'success' => true,
                    'data' => $img->toArray()
                ]);;

            }
    }

您好,请检查您是否具有正确的权限。错误是什么?还是没有错误?。检查图像是否正在另一个目录中保存。是否可以将此$input['imagename']替换为$filename并检查?在您的邮递员请求中,您应该指定图像属性并将文件附加到那里,我在您的屏幕截图上看不到这一点。首先,如果尚未在公用文件夹中创建uploads/images目录,请创建该目录并设置读写权限。然后试试看again@MarcoFeregrino它不会保存到任何位置directory@ViperTecPro我已经做了所有这些,但仍然没有保存。拜托,我似乎不理解代码。我的域名是images。帖子、站点id、徽标在哪里?我将在何处添加此enctype=multipart/form data我通过删除不需要的代码修改了答案。检查它。Symfony\Component\Debug\Exception\fatalthrowable错误:Class&039;App\Http\Controllers\Session&039;在第45行的/Applications/XAMPP/xamppfiles/htdocs/flavourvoals/Server/app/Http/Controllers/ImagesController.php文件中找不到不工作,未显示错误,但未将图像保存到指定目录,也未保存到数据库谢谢,但我有另一个问题。请问,我如何检索保存的图像并创建一个与另一个已保存图像的合并副本