Agbaje's avatar

Laravel File Upload

I am trying to upload a file to the database and save it in the public folder. but whenever I upload any file, it gets reduced in size to 24kb. My Function

$this->validate($request, [
            'point'             => 'required|numeric',
            'name'              => 'required',
            'link'              => 'required',
            'image_link'        => 'required',
            'days'              => 'required|numeric',
            'doc'               => 'nullable|mimes:doc,docx,pdf',
        ]);

		if ($request->hasFile('doc')) {
            $course_file = $request->file('doc');
            $filename = time() . '_' . $request->name . '.' . $course_file->getClientOriginalExtension();
            $location = 'assets/' . $filename;
            $upload_name = $filename;

            File::put($location, $course_file);
        }
0 likes
5 replies
tykus's avatar

Try using the UploadedFile instance itself rather than File::put, which :

$path = $request->file('doc')->storeAs(public_path('assets'), $filename);
1 like
Agbaje's avatar

@tykus No matter what the size is, it reduces to 24kb, which renders the file invalid or corrupted

tykus's avatar

@Agbaje I asked where you were storing the file(s) previously.

Please or to participate in this conversation.