raviSoni's avatar

Problem in uploading a file

Hello everyone i need to upload a file in database but i got error

my view file is

<div class="modal-content">
 <div class="modal-header">
 <button type="button" class="close" data-dismiss="modal">&times;</button>
   <h4 class="modal-title">File upload form</h4>
    </div>
    <div class="modal-body">
    <!-- Form -->
    <form method="post" action="{{ route('upload.file') }}" enctype="multipart/form-data">
    {{ csrf_field() }}
    Select file : <input type='file' name='file' id='file' class='form-control' ><br>
    <input type='submit' class='btn btn-info' value='Upload' id='upload'>
    </form>
    </div>

my controller is

public function store(Request $request) { if($request->hasFile('file')) {

        $filename = $request->file->getClientOriginalName();
        $fileExtension=$request->file->getClientOriginalExtension();
        $request->file->storeAs('public/storage',$filename,$fileExtension);
        $file = new File;
        $file = save();
        return 'yes';
    }
    return $request->all();
}
public function showUploadForm()
{
    return view('vendorQuote_details');
}

my route is

Route::get('file','Vendor_dashboard@showUploadForm')->name('upload.file');
Route::post('file','Vendor_dashboard@store');
0 likes
14 replies
Sinnbeck's avatar

What is save()? Some function you have made yourself?

What should these lines do?

 $file = new File;
 $file = save();
raviSoni's avatar

no i am following a tutorial according to that tutorial this function is written

raviSoni's avatar

I think these lines save data into database

Sinnbeck's avatar

What tutorial are you following? Do you have a link?

Normally it would be something like this

$file = new File;
$file->name = 'foobar';
$file->save();
munazzil's avatar

Can you show which model are you going save?

munazzil's avatar

return $request->all(); this should be change according to below because your are only returning data not saving,

       Model::create($request->all());
Sinnbeck's avatar

@munazzil Not if following the tutorial. And besides I am quite sure that has nothing to to with the error.

@ravisoni Can you post the content of config/filesystems.php ?

1 like
raviSoni's avatar
<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    /*
    |--------------------------------------------------------------------------
    | Default Cloud Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Many applications store files both locally and in the cloud. For this
    | reason, you may specify a default "cloud" driver here. This driver
    | will be bound as the Cloud disk implementation in the container.
    |
    */

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
    |
    */

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

];
raviSoni's avatar
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class RequestQuote extends Model
{
    use SoftDeletes;

    protected $table = 'request_quotes';

    protected $hidden = [

    ];

    protected $guarded = [];

    protected $dates = ['deleted_at'];
}
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Ok that is fine.

Try leaving out the 3rd parameter in storeAs. If it a string it tries to use that as the disk

$request->file->storeAs('public/storage',$filename);

Please or to participate in this conversation.