public function storeAttachment() { $parameters = $this->request->route()->parameters(); $attachments = $this->request->input('attachments'); $attachmentsResponse = []; foreach ($attachments as $attachment) { $idAttachment = Attachment::max('id_016'); $idAttachment++; // move file from temp file to attachment folder File::move(public_path() . config($this->request->input('routesConfigFile') . '.tmpFolder') . '/' . $attachment['tmpFileName'], public_path() . config($this->request->input('routesConfigFile') . '.attachmentFolder') . '/' . $parameters['object'] . '/' . $parameters['lang'] . '/' . $attachment['fileName']); $attachmentsResponse[] = Attachment::create(['id_016' => $idAttachment, 'lang_id_016' => $parameters['lang'], 'resource_id_016' => $this->request->input('resource'), 'object_id_016' => $parameters['object'], 'family_id_016' => null, 'library_id_016' => $attachment['library'], 'library_file_name_016' => $attachment['libraryFileName'], 'sorting_016' => null, 'name_016' => null, 'file_name_016' => $attachment['fileName'], 'mime_016' => $attachment['mime'], 'size_016' => filesize(public_path() . config($this->request->input('routesConfigFile') . '.attachmentFolder') . '/' . $parameters['object'] . '/' . $parameters['lang'] . '/' . $attachment['fileName']), 'type_id_016' => $attachment['type']['id'], 'type_text_016' => $attachment['type']['name'], 'width_016' => empty($attachment['width']) ? null : $attachment['width'], 'height_016' => empty($attachment['height']) ? null : $attachment['height'], 'data_016' => json_encode(['icon' => $attachment['type']['icon']])]); } $response = ['success' => true, 'attachments' => $attachmentsResponse]; return response()->json($response); }
/** * Function to store attachment elements * * @access public * @param \Illuminate\Support\Facades\Request $attachments * @param string $lang * @param string $routesConfigFile * @param integer $objectId * @param string $resource * @return boolean */ public static function storeAttachments($attachments, $routesConfigFile, $resource, $objectId, $lang) { if (!File::exists(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang)) { File::makeDirectory(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang, 0755, true); } foreach ($attachments as $attachment) { $idAttachment = Attachment::max('id_016'); $idAttachment++; $width = null; $height = null; if ($attachment->type->id == 1) { list($width, $height) = getimagesize(public_path() . $attachment->folder . '/' . $attachment->tmpFileName); } // move file fom temp file to attachment folder File::move(public_path() . $attachment->folder . '/' . $attachment->tmpFileName, public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang . '/' . $attachment->fileName); Attachment::create(['id_016' => $idAttachment, 'lang_id_016' => $lang, 'resource_id_016' => $resource, 'object_id_016' => $objectId, 'family_id_016' => empty($attachment->family) ? null : $attachment->family, 'library_id_016' => $attachment->library, 'library_file_name_016' => empty($attachment->libraryFileName) ? null : $attachment->libraryFileName, 'sorting_016' => $attachment->sorting, 'name_016' => empty($attachment->name) ? null : $attachment->name, 'file_name_016' => empty($attachment->fileName) ? null : $attachment->fileName, 'mime_016' => $attachment->mime, 'size_016' => filesize(public_path() . config($routesConfigFile . '.attachmentFolder') . '/' . $objectId . '/' . $lang . '/' . $attachment->fileName), 'type_id_016' => $attachment->type->id, 'type_text_016' => $attachment->type->name, 'width_016' => $width, 'height_016' => $height, 'data_016' => json_encode(['icon' => $attachment->type->icon])]); } }