I am trying to upload files (they can be any type), and I have a problem uploading file with certain way.
I am able to upload a file correctly using $request->file('file_name')
and Storage::disk($disk)->put($path, $file);
. However, $file
parameter can only be through $request->file('file_name')
.
However, because of the way I want to upload multiple orders with multiple files like below:
Controller
foreach ( $filesArray as $key => $files ) {
$path = 'order/'.$order->id;
if ( isset($files[$i]) && !empty($files[$i]) ) {
for ( $j = 0; $j < count($files[$i]); $j++ ) {
$uploadedFile = FileHelper::upload($files[$i][$j], $path);
$orderFile = [];
$orderFile['order_id'] = $order->id;
$orderFile['file_id'] = $uploadedFile->id;
OrderFileModel::create($orderFile);
}
}
}
FileHelper
static public function upload($file, $path, $disk = 's3')
{
$fileOrm = new FileModel;
$fileOrm->size = $file->getSize();
$fileOrm->extension = $file->getExtension();
$fileOrm->bucket_name = self::$BUCKET_NAME;
$fileOrm->type = self::getFileType($file->getExtension());
$fileOrm->key = Storage::disk($disk)->put($path, $file);
$fileOrm->created_time = now();
$fileOrm->save();
return $fileOrm;
}
I've also attached images where I see the difference. One with $request->file('file_name')
and the other with just $request->file_name
which is blob type.
The image below would return error saying fstat() expects parameter 1 to be resource, object given
How could I solve this problem?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2I0IA1n
via IFTTT
Aucun commentaire:
Enregistrer un commentaire