Php 如何对不同大小的图像进行两次上传

Php 如何对不同大小的图像进行两次上传,php,laravel,Php,Laravel,你好,我有一个项目我在做,它有一些问题 这里的问题是,我需要两次获取文件,一次用于移动,另一次用于调整大小 这是我的代码,我应该在这里做什么 public function update_image(Request $request) { $ad = Ad::where('id',$request->ad_id)->first(); $photos= explode('||',$ad->photos); $thumbnails= explode('||

你好,我有一个项目我在做,它有一些问题

这里的问题是,我需要两次获取文件,一次用于移动,另一次用于调整大小

这是我的代码,我应该在这里做什么

 public function update_image(Request $request)
{
    $ad = Ad::where('id',$request->ad_id)->first();
    $photos= explode('||',$ad->photos);
    $thumbnails= explode('||',$ad->thumbnails);
    $number =  count($photos);
    $length = strlen($photos[$number-1]);
    $last_image_number = $photos[$number-1][$length - 5];
    // dd($photos[$number-1][$length - 5]);
    $last_image_number++;
    $image = $request->file('image');
    $image_name = 'preview_'.$last_image_number.'.'.$image->getClientOriginalExtension();
    $previews_path = public_path().'/uploads/images/'.$ad->ad_id.'/previews/';
    $thumbs_path = public_path().'/uploads/images/'.$ad->ad_id.'/thumbnails/';
    // $im = Image::make($image->getFullPath());
    chmod($previews_path,0777);
    $image->move($previews_path,$image_name);
    $photos[]= '/'.$ad->ad_id.'/previews/'.$image_name;
    $ad->photos = implode('||',$photos);
    $photo_path = basename($previews_path . $image_name);
    $ad->save();

    list($width, $heigh) = getimagesize($previews_path.$photo_path);
    $photo_path->move($thumbs_path,'ddd.jpg');
    dd($photo_path);
    // dd($width);
    $ratio = $width/ $heigh;
    $target_width = $width / $ratio;
    $target_height = $target_width / $ratio;
    $photo_path->resize($target_width,$target_height);

    $thumb_name= 'thumbnail_'.$last_image_number.'.'.$image->getClientOriginalExtension();
    $image->move($thumbs_path , $thumb_name);
    $thumbnails [] = '/'.$ad->ad_id.'/thumbnails/'.$thumb_name;
    $ad->thumbnails = implode('||',$thumbnails);
    $ad->save();


    // dd($image_name);
    return response()->json(['success'=>true]);

你能说得更具体些吗?
public function store(Request $request)
    {
        $this->validate($request,[
            'title' =>'required',
            'image' => 'mimes:jpeg,jpg,bmp,png',

        ]);



          $image = $request->file('image');
        $slug = str_slug($request->title);
        if (isset($image))
        {
            $currentDate = Carbon::now()->toDateString();
            $imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
            $image_resize = Image::make($image->getRealPath()); 


            if (!file_exists('storage/uploads/category'))
            {
                mkdir('storage/uploads/category',0777,true);
            }
            $image_resize->resize(1600,1066);
            $image_resize->save('storage/uploads/category/'.$imagename);

            if (!file_exists('storage/uploads/post'))
            {
                mkdir('storage/uploads/post',0777,true);
            }
            $image_resize->resize(550,600);
            $image_resize->save('storage/uploads/post/'.$imagename);
        }else{
            $imagename = "default.png";
        }

         $post = new Post();
        $post->user_id = Auth::id();
        $post->title = $request->title;
        $post->slug = str_slug($request->title);
        $post->image = $imagename;
        $post->save();
        Toastr::success('Post Successfully Save:)','Success');
        return redirect()->route('admin.post.index');

    }