페이지 작성 변경-이미지 이름이 문제가 Laravel

0

질문

이것은 아래 페이지를 만들고 원하는 이미지를 변경하는 이름을 따라 동영상 id 에 Laravel 프로젝트입니다. 그러나 때로 업로드 이미지를 저장 만들기 페이지에 저장할 데이터베이스 이름이 될/tmp/phpRXDHFh,나는 원하는 이미지의 이름을 저장하에서의 데이터베이스로 공개/비디오/themnull/비디오 id 입니다.png. 이 문제를 해결하는 방법?

여기에는 코드를 컨트롤러

public function store(Request $request)
{

    $data = $request->validate([
        'video_path'   => 'nullable|mimes:mp4,avi,mpeg,ogx,oga,ogv,ogg,webm| max:25600',
        'user_id'      => 'required | integer',
        'category_id'  => 'required | integer',
        'video_section_id'  => 'required | string',
        'title'         => 'required | string',
        'post_date'    => 'nullable | date',
        'description'   => 'nullable | string',
        'youtube_link'  => 'nullable | string',
        'image_path'    => 'nullable | image |  mimes:jpeg,png,jpg,gif | max:2140',
    ]);


    if ($request->check_type == 1) {

        $data['type'] = 'link';
    }

    $data['post_date'] = $request->post_date ?? date('Y-m-d');

    if ($request->hasFile('video_path') != '') {

        $art_video = $request->file('video_path');
        $ad_video_name = uniqid('video_') . Str::random('10') . '.' . $art_video->getClientOriginalExtension();
        $created_id = 0;

        $video_image_path = $request->file('image_path');
        $video_image_name =  $art_video->id. '.' . $video_image_path->getClientOriginalExtension();
        $video_image_path_resize = Image::make($video_image_path->getRealPath());
         $video_image_path_resize->resize(400, 200);
        if ($video_image_path->isValid()) {

            $video_image_path_resize->save(public_path('video/themnull/' . $video_image_name));
            $video_image_path = 'public/video/themnull/' . $video_image_name;
            $data['image_path'] = $video_image_path;
        }

        if ($art_video->isValid()) {
            $fileName = $ad_video_name;
            $foldername = '/video';
            $name = $fileName;
            $video_path = $art_video->storeAs($foldername, $name, 'public');

            $data['youtube_link'] = null;
            $data['type'] = 'directly';
            $data['video_path'] = 'public/' . $video_path;
            $created_id = Video::create($data);
        }
    } else {
        $created_id = Video::create($data);
    }
    if ($request->filled('tag_name')) {
        if ($created_id) {
            $last_inserted_id = $created_id->id;
            foreach ($request->tag_name as $tag_name) {
                $data2 = ([
                    'video_id' => $last_inserted_id,
                    'tag_name' => $tag_name
                ]);
                $created_id = VideoTag::create($data2);
            }
        }
    }
    try {
        $this->successfullymessage('Video  Added successfully ');
        return redirect()->back();
    } catch (\Exception $e) {
        $this->failmessage($e->getMessage());
        return redirect()->back();
    }
}
file-upload image image-upload laravel
2021-11-24 04:55:44
1

최고의 응답

0
$extension = $request->file('image_path')->getClientOriginalName();
$fileName = time().'-'.$art_video->id..'.'.$extension; // you can use time with name if not, then use only $art_video->id..'.'.$extension;.
       
// $file->move('video/thumbnail',$fileName); to store in public folder

//  If you want to keep files in storage folder, you can use following : -

Storage::disk('public')->put('video/thumbnail/'.$fileName,File::get($request->file('image_path')));

// Dont't forget to run 'php artisan storage:link'
// It will store into your storage folder and you can access it by Storage::url('file_path)
2021-11-24 05:41:42

안녕하세요,어디를 넣을 필요가 또는 교체가 필요하십니까?
Sam

는 곳에서 당신은 수정하는 이미지의 이름과 저장소의 이미지입니다. $video_image_path = $request->file('image_path'); $video_image_name = $art_video->id. '.' . $video_image_path->getClientOriginalExtension(); 이는 대신 $video_image_path$video_image_name top $extension = $request->file('image_path')->getClientOriginalName(); $fileName = time().'-'.$art_video->id..'.'.$extension;
Masudul Hasan Shawon

될 수 있습하려는 상점의 이미지기 $video_image_path_resize->save(public_path('video/themnull/' . $video_image_name)); 그래서 다음을 거- Storage::disk('public')->put('video/thumbnail/'.$fileName,File::get($request->file('image_path'))); 을 확인하고 저장한 파일입니다.
Masudul Hasan Shawon

안녕하세요,여전히 동일한 이미지는 이름 저장소에서 데이터베이스는 여전히/tmp/phpPfJm8Q
Sam

내가 필요한 이미지는 이름 저장소에서 데이터베이스(_경로)같은 공개/비디오/themnull/비디오 id 입니다.png
Sam

기 때문에 당신이 저장하기 $data 보다는 수정이다. 그 이유는 시스템이 temp 이름입니다. 저장소 'video/thumbnail'."/".$fileName 귀하의 데이터베이스입니다. 다음과 같 저장할 수 있습니다 Video::create(['file_path' => 'video/thumbnail'."/".$fileName, 'foo' => 'bar', '...' => '...']).
Masudul Hasan Shawon

그래서 의미가 필요한 변경$데이터['youtube_link']=null;$데이터['유형']='직접';$데이터['video_path']='공개/'. $video_path;$created_id=비디오::create($data);
Sam

안녕 Masudul,그래서 어떻게?
Sam

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................