canadianlover's avatar

File won't upload

I am designing a e-commerce website and right now I'm working on the admin panel. I need to upload a file and when I do it fails. All I get is a redirect to the form. My databases doesn’t update either. What am I doing wrong? Controller:

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

    if (Input::hasFile('filename')) {
        $file = $request->file('filename');
        $file->move('uploads', $file->getClientOriginalName());

        echo "File Uploaded";

    }```

View

    <hr />
    <content>
        <div class="form-group">
        {!! Form::open(['route' => 'item.store', 'files' => true]) !!}
        {!! Form::label('name', "Name") !!}
        {!! Form::text('name', null, ['class' => 'form-control']) !!}

       {!! Form::label('filename', "File Name") !!}
        {!! Form::file('filename', null, ['class' => 'form-control']) !!}

        {!! Form::label('description', 'Description') !!}
        {!! Form::textarea('description', null, ['class' => 'form-control']) !!}
        {!! Form::submit('Add Item', ['class' => 'btn btn-primary form-control']) !!}

    </content>
</div>```
0 likes
4 replies
kreierson's avatar

Maybe it has something to do with the file size?

PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less. Try increasing the following values in php.ini, for example: memory_limit = 32M upload_max_filesize = 24M post_max_size = 32M.

Or just try uploading a smaller file first to test.

DarkRoast's avatar

Uploads directory might need to be: public_path().'/uploads'

canadianlover's avatar

I tried your suggestion, both changing the upload path and file size, but that didn't help me. I tried running this:

    {


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

//        if (Input::hasFile('filename')) {
//            $file = $request->file('filename');
//            $file->move(public_path().'/uploads', $file->getClientOriginalName());
//
//            echo "File Uploaded";
//
//        }
        dd(Input::all());

}

Upon submision of this form, I am simply redirected back to the page, I do not see the debug test debug text. I will try submitting the form agian using a different method.

canadianlover's avatar

I found my answer. Requests/CreateItem should look like this:

'filename' => 'required|min:7',

instead of

filename, 'required|min:7

Please or to participate in this conversation.