pavelrogala's avatar

File request returns corrupt file \ randomized filename

I'm trying to upload a file to store via Laravel's storage Api. My code is as following:

public function postAvatar(Request $request)
    {
        $upload = $request->file('avatar');
        $extension = $upload->getClientOriginalExtension();
        Storage::disk('local')->put($upload->getFilename().'.'.$extension,  $upload);

        return redirect('/dashboard');
    }

I tried uploading a something.sql file but the file turns into something like phpZMYfrZ.sql with a content of /tmp/phpZMYfrZ ... any idea as to what I'm doing wrong?

0 likes
3 replies
pavelrogala's avatar

dd($upload); returns:

UploadedFile {#30 ▼
  -test: false
  -originalName: "create_tables.sql"
  -mimeType: "application/sql"
  -size: 7676
  -error: 0
}
donpaper662's avatar

Exactly same problem here. I read the docs but still didn't find a solution.

Please or to participate in this conversation.