0
votes

I'm using Laravel 5.1.
Uploading of filetypes jpeg, gif, png is working, but pdf, doc, docx, txt filetypes are not working.

Here is my view

{!! Form::label('department','Department', ['class'=>'col-sm-2 control-label'] ) !!}
<div class="col-sm-10">
    {!! Form::select('department', $departmentList, null, ['class'=>'form-control']) !!}

    <span style="color: red">{{ $errors->first('department') }}</span>
</div>
<div class="form-group">

    {!! Form::label('document','Chose a file or Document', ['class'=>'col-sm-2 control-label'] ) !!}

    <div class="col-sm-10">

        {!! Form::file('file', null, ['class'=>'form-control']) !!}
        <p class="help-block">Upload your document in pdf, doc. jpg, png, tif, gif</p>
        <span style="color: red"> {{ $errors->first('file') }}</span>
    </div>
</div>
{!! Form::close() !}}

my FormRequest

public function rules()
{
    return [
        'user_id'=>'integer',

        'department'=>'required',
        'file'=>'required|mimes:application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf, jpeg, png, gif'
    ];
}

}

and my controller

public function update($id, RepositoryRequest $request)
    {
    $repository = Repository::findOrFail($id);
   $repository->department = $request->input('department');



    $file = \Input::file('file');
    $filename = date('Y-m-d-H:i:s').'-'.$file->getClientOriginalName();

    $path =public_path('/img/repository/').$filename ;
    \Image::make($file->getRealPath())->resize(468, 249)->save($path);

    $repository->file = 'img/repository/'.$filename;

    $repository->save();

    return redirect('/')->with('flash_message', 'You have successfully updated the repository');

This is the error:

NotReadableException in Decoder.php line 21: Unable to read image from file (/tmp/phpdNQvEG).

1

1 Answers

2
votes

try use http://laravel.com/docs/5.1/filesystem to stor files.

public function UploadImage() {
$file = Request::file('filefield');
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put($file->getFilename().'.'.$extension,  File::get($file));
$entry = new Upload();
$entry->mime = $file->getClientMimeType();
$entry->original_filename = $file->getClientOriginalName();
$entry->filename = $file->getFilename().'.'.$extension;

$entry->save();

$file = Storage::disk('local')->get($entry->filename);

return (new Response($file, 200))->header('Content-Type', $entry->mime);

}