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?
Any advice or suggestion would be appreciated. Thank you.


$path = $request->file('avatar')->store( 'avatars/'.$request->user()->id, 's3' );? Otherwise you'll need to use something like file_get_contents($files[$i][$j]) to get the contents of the temp file and handle it manually.file_get_contentsto get the contents? According to the doc,file_get_contentsrequired the name of the file in the first parameter, however$files[$i][$j]is an object.