dongshao2967 2016-02-06 19:30
浏览 73

Laravel:在localhost上传文件时遇到麻烦

I've trouble getting the file upload working with Laravel on my Windows 7 system. There is no issue with uploading the files but when I see the destination directory the uploaded file is not present.

After searching in Google and forums I found that there may be a problem with the 'Temp' directory.

The output of dd(sys_get_temp_dir()) is C:\Users\RAGHAV~1\AppData\Local\Temp.

However there is no directory called RAGHAV~1(I've enabled to see the hidden folders). In php.ini the upload_tmp_dir is set to C:\xampp\tmp.

Is there any conflict between these settings? Can you please help me to get the file upload working?

The code in the controller that process the uploaded files:

$validator = $this->brandValidator($request->all());

if ($validator->fails()) {
    $this->throwValidationException(
        $request, $validator
    );
}

$image_directory = public_path() . '/Uploads/Products/';

$result = $request->file('image')->move($image_directory);

$brand_name = $request->input('brand_name');
$image = $image_directory . $request->file('image')->getClientOriginalName();

$id = Brand::create([
    'brand_name' => $brand_name,
    'image' => $image,
]);
  • 写回答

1条回答 默认 最新

  • dongpin2969 2016-02-06 19:54
    关注

    You have not specified the path for the file. Simply replace this

    $image_directory = public_path() . '/Uploads/Products/';
    
    $result = $request->file('image')->move($image_directory);
    

    with this

    $file = $request->file('image');
    
    $filename =  $file->getClientOriginalName().'.' . $file->getClientOriginalExtension();
    
    $file->move(public_path('Uploads/Products/'), $filename);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效