I'm using jquery file-uploader
to upload files with this
$('#fileupload').fileupload({
formData: {_token: csrf_token },
dataType: 'json',
done: function (e, data) {
addFileToTable(data);
}
});
and try to save it in Laravel
with a random name and the extension like this
if ($request->hasFile('files')) {
$filepath = config('paths.files');
$files = $request->file('files');
$file = $files[0];
$fileName = md5($file . microtime()) . '.' . $file->extension();
$file->storeAs(
$filepath, $fileName, 'public'
);
$isImage = substr($file->getMimeType(), 0, 5) == 'image';
$fileObj = File::create([
'name' => $fileName,
'path' => '/storage/'.$filepath.$fileName,
'isImage' => $isImage,
'user_created' => auth()->id()
]);
return response()->json(array('file' => $fileObj), 200);
}
but the problem is when i try to upload files like .css
, .js
, etc. Laravel
sees the extension as .txt
and saves it as .txt
file
I don't know if the problem is in the Laravel
or jquery-fileuploader
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire