SangminKim's avatar

Laravel 5 & Mamp - stores weird path when uploading a file

    public function store(AdminProgramRequest $request)
    {
        $request = $this->move_image_file($request, 'thumbnail');
        $request = $this->move_image_file($request, 'korean_brochure');
        $request = $this->move_image_file($request, 'english_brochure');
        $request = $this->move_image_file($request, 'chinese_brochure');

        Program::create($request->all());

        return redirect('dashboard/program_category/'.$request->program_category_id.'/edit');
    }

    

    private function move_image_file($request, $input_name)
    {
        if($request->hasFile($input_name)){
            $filename = $request->file($input_name)->getClientOriginalName();
            $request->file($input_name)->move(
                base_path() . '/public/pdf/program_category/' . $request->program_category_id . '/' , $filename
            );    
            $request->merge([

                // I think this is where
                // /private/var/folders/_l/9jdb6p2s3ms4vh8jv0mp_43w0000gn/T/phphi95xw 
                // stuff gets stored in $request even if
                // $filename has the uploaded filename for sure.
                $input_name => $filename
       
                // This hardcode also works in the same way and stores weird path in db... WHY!?
                // $input_name => 'whats_going_on.jpg'  
            ]);
        }
        return $request;
    }

This is driving me nuts. I'm pretty sure that $filename has the filename of the uploaded file.

  1. I've double checked if $filename has a correct value. Yes.
  2. I've hardcoded and given a randome filename to $filname. Still doesn't work but stores the weird path thing.
  3. I've tested if files are being uploaded correctly. and Yes.
  4. I've checked view files. Since #3 is working, of course Yes.

Now, I'm suspecting MAMP.

Has anyone experienced the same issue with Laravel5 and Mamp on OSX?

0 likes
1 reply
SangminKim's avatar
SangminKim
OP
Best Answer
Level 4

Fixed. Laravel 5 got confused with my local variable and $request->file('same as local variable name'). Dunno why but solved it by using different name.

Please or to participate in this conversation.