Laravel 5& Mamp - 在上传文件时存储奇怪的路径

时间:2015-07-27 20:43:44

标签: php laravel mamp

/**
 * Store a newly created resource in storage.
 *
 * @param  Request  $request
 * @return Response
 */


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;
}

这让我疯了。我很确定$ filename有上传文件的文件名。

  1. 我已经仔细检查过$ filename是否有正确的值。是。
  2. 我已经硬编码并给$ filname一个randome文件名。仍然没有工作,但存储了奇怪的道路。
  3. 我测试过是否正确上传文件。是的。
  4. 我检查了查看文件。由于#3正在运行,当然是。
  5. 现在,我怀疑是MAMP。

    有没有人在OSX上遇到与Laravel5和Mamp相同的问题?

0 个答案:

没有答案