XAMPP文件上传错误

时间:2015-11-22 21:32:35

标签: php laravel-5 xampp

我使用表单上传图片文件(约200k)。并将其移动到后端的指定文件夹中。但是当我在这个文件夹中打开这个文件时,它不是一个图像文件,它的大小只有45个字节。我尝试编辑它,文件内容是" XAMPP / xamppfile / temp / phpdBLLad"而不是二进制代码。只需在我的文件中保存[' tmp_name']。

前端:

<form action="/photos" method = "POST" enctype="multipart/form-data">

    <div class = 'col-md-12 red_line2' style = "height:40px;width:30%; color:black">

        <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
        <input type = "hidden" name = 'album_id' value = '{{$album->id}}'>
        <input id = 'addimg' name = 'myimage' type="file" multiple style="display:none" />
        <button type = 'button' id = 'fileUpload' class="btn btn-link btn-lg"  data-target="#image_preview" aria-expanded="false" aria-controls="collapseExample">
            <span class="fa fa-camera"></span>
        </button>
        <button type="button" class="btn btn-link btn-lg" >
            <span class="fa fa-trash"></span>
        </button>
        <button type="button" class="btn btn-link btn-lg" >
            <span class="fa fa-pencil-square-o"></span>
        </button>

    </div>
    <div class = 'col-md-12'>
        <div class = "extraspace-small"></div>
    </div>
    <div class = 'col-md-12'>
        <div class = "collapse" id = "image_preview">
        <div class = 'pull-right myfloater'>
            <button id = "upload" type = "submit" class="btn btn-sm btn-primary vcenter">
                UPLOAD
            </button>
            <button id = "cancle_upload" type = "button" class="btn btn-sm btn-danger vcenter">
                CANCLE
            </button>
        </div>
        <div class = "well mywell" id = 'preview_container'>
        </div>
        </div>
    </div>
    </form>

后端:

    public function store(Request $request)
{
    $rules = array(
      'album_id'=>'required',
      'myimage'=>'required|image'
    );        

    $validator = Validator::make($request->all(), $rules);        

    if($validator->fails()){
        var_dump($validator->errors());
    }

    $data = $request->only('album_id','myimage');
    $destinationPath = 'albums/';
    $file = $request->file('myimage');
    $filename = $file->getClientOriginalName();
    Storage::put($destinationPath.$filename, $data['myimage']);
    $album = Images::create(array(
      'image' => $filename,
      'album_id' => $request->album_id,
    ));

    return redirect('photos/'.$request->album_id);//,['id'=>$album->id]
}

0 个答案:

没有答案