jeudi 1 février 2018

Laravel store form file in alternative folder and access in request

At the moment, my application is stored on a Linux server (I do not have control of the server, so server adjustments are out of the question).

In my application there is a form where users can upload excel and csv files, the request is then being passed into a laravel validation request as shown below.

Whenever I try to upload the file, it claims the file is not there.

Laravel Request

public function rules()
{
    return [
        'user-file' => 'required|mimes:csv,xslx',
    ];
}

I've already figured out my problem, its that the default tmp folder stores and then instantly deletes the file so that the request cant find the file, so that by the time the above code runs, the file is no longer there and just returns an error.

How would I change the folder where the files are stored and point to there instead inside a request?

Something like

public function rules()
{
 $name = 'user-file' .'.'. $this->file('user-file')->getClientOriginalExtension();
 $move = $this->file('user-file')->storeAs('/newdirectory',$name);
 return [
    //Point to the new file inside 'newdirectory' for the below request validation
    'user_file' => 'required|mimes:csv,xslx',
 ];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire