/** * @POST("/uploading_data") * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function uploading_data(Request $request) { $photos = $request->input('photos'); $category_id = $request->input('category_id'); if ($request->input('shop_id')) { $shop_id = $request->input('shop_id'); $shop = Shops::find($shop_id); if ($shop && !$shop->canAddItem()) { return redirect()->route('shops.my'); } foreach ($photos as $photo) { foreach ($photo as $item) { $attachment = new Attachment(); $attachment->name = $item['aid']; $attachment->path = $item['src_big']; $attachment->url = $item['src_big']; $attachment->save(); $shop_item = new ShopItems(); $shop_item->name = 'Название'; $shop_item->description = $item['text']; $shop_item->shop_id = $shop_id; $shop_item->category_id = $category_id; if ($attachment) { $shop_item->attachment()->associate($attachment); } $shop_item->save(); } } } }
/** * Returns a new form for the specified work order attachment. * * @param WorkOrder $workOrder * @param Attachment $attachment * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, Attachment $attachment) { return $this->form->of('work-orders.attachments', function (FormGrid $form) use($workOrder, $attachment) { $files = true; if ($attachment->exists) { $url = route('maintenance.work-orders.attachments.update', [$workOrder->getKey(), $attachment->getKey()]); $method = 'PATCH'; $form->submit = 'Save'; $form->with($attachment); } else { $url = route('maintenance.work-orders.attachments.store', [$workOrder->getKey()]); $method = 'POST'; $form->submit = 'Upload'; } $form->attributes(compact('url', 'method', 'files')); $form->fieldset(function (Fieldset $fieldset) use($attachment) { if ($attachment->exists) { // If the attachment exists we'll provide the ability // to only change the attachments name. $fieldset->control('input:text', 'name')->label('Attachment Name'); } else { // Otherwise we'll allow the user to upload multiple // attachments at once for the specified work order. $fieldset->control('input:file', 'files[]')->label('Files')->attributes(['multiple' => true]); } }); }); }
/** * Deletes the current attachment as well as the file. * * @param Filesystem $filesystem * * @throws \Exception * * @return bool */ public function handle(Filesystem $filesystem) { try { if ($filesystem->delete($this->attachment->getStorageFilePath())) { return $this->attachment->delete(); } } catch (FileNotFoundException $e) { // } return false; }
public function actionDeleteAttachment($id) { $attachment = Attachment::findOne($id); $document_id = $attachment->document_id; $attachment->delete(); return $this->redirect(['update', 'id' => $document_id]); }
public function getAllAttachments() { if ($this->owner->isNewRecord) { return []; } return Attachment::find()->where(['table' => $this->owner->tableName(), 'object_id' => $this->owner->id])->orderBy(['id' => SORT_ASC])->all(); }
public function image(UploadedFile $file = null, Attachment $attachment = null) { if ($file == null) { return; } if ($attachment == null) { $attachment = new Attachment(); } // dd($file->getClientOriginalExtension()); $name = time() . '.' . $file->getClientOriginalExtension(); $file->move(public_path() . $this->path . 'attachments/', $name); $attachment->name = $name; $attachment->path = $attachment->getUploadPath() . $name; //$attachment->user_id = Auth::user()->id; $attachment->save(); return $attachment; }
/** * Updates an existing Document model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { $fileUploadData = Attachment::data($model->id); return $this->render('update', ['model' => $model, 'fileUploadData' => $fileUploadData]); } }
public function actionSortable() { /** @var $modelList Attachment[]*/ $data = \Yii::$app->request->get('data'); $modelList = Attachment::find()->where(['id' => $data])->orderBy([new Expression('FIND_IN_SET(id,"' . implode(',', $data) . '")')])->all(); foreach ($modelList as $k => $model) { $model->position = $k + 1; $model->save(false, ['position']); } }
/** * @inheritdoc */ public function beforeDelete() { if (parent::beforeDelete()) { // при удалении документа, удаляем все файлы к нему Attachment::deleteAll(['document_id' => $this->id]); return true; } else { return false; } }
public function upload() { if ($this->validate()) { foreach ($this->files as $file) { $attachment = new Attachment(); $attachment->document_id = $this->document_id; $attachment->name = \Yii::$app->security->generateRandomString() . '.' . $file->extension; $attachment->original_name = $file->baseName . '.' . $file->extension; $attachment->size = $file->size; if ($attachment->validate()) { if ($file->saveAs(\Yii::$app->basePath . '/web/uploads/' . $attachment->name)) { $attachment->save(); } } } return true; } else { return false; } }
public function run() { $faker = Faker\Factory::create(); DB::table('shops')->delete(); foreach (range(1, 3) as $index) { $city_id = \App\Models\Cities::orderBy(DB::raw('RAND()'))->first()->id; $user_id = rand(1, 3); $profile_id = \ZaWeb\Shops\Models\ShopProfile::orderBy(DB::raw('RAND()'))->first()->id; $attachment_id = \App\Models\Attachment::orderBy(DB::raw('RAND()'))->first()->id; \ZaWeb\Shops\Models\Shops::create(['user_id' => $user_id, 'city_id' => $city_id, 'capacity' => 300, 'attachment_id' => $attachment_id, 'profile_id' => $profile_id, 'created_at' => date('Y-m-d G:i:s'), 'updated_at' => date('Y-m-d G:i:s')]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $document_id) { $query = Attachment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'size' => $this->size, 'document_id' => $document_id, 'order' => $this->order]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'original_name', $this->original_name]); return $dataProvider; }
/** * Загрузка файла. При успехе создание и сохранение модели Attachment * @return boolean */ public function upload() { $ext = $this->file->extension; $origName = $this->file->baseName . '.' . $ext; $size = $this->file->size; $fileName = md5(uniqid()) . '.' . $ext; $path = $this->getUploadDir() . '/' . $fileName; if ($this->file->saveAs($path)) { // создаем и сохраняем модель Attachment $attachment = new Attachment(); $attachment->document_id = $this->documentID; $attachment->origname = $origName; $attachment->filename = $fileName; $attachment->mimetype = FileHelper::getMimeType($path); $attachment->size = $size; if ($attachment->save()) { return true; } else { // если ничего не получилось, удаляем загруженный файл unlink($path); } } return false; }
public function loadAttachment($id) { if (($document = Attachment::findOne($id)) !== null) { return $document; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function run() { \Illuminate\Support\Facades\DB::table('attachment')->delete(); Model::unguard(); \App\Models\Attachment::create(['name' => 'test', 'path' => 'tesst']); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Banner $banner) { $image = Attachment::where('id', $banner->attachment_id); $banner->delete(); $image->delete(); return redirect()->route('admin.banner.index'); }
/** * Загрузка файлов */ public function uploadFiles($dirName = null) { $ds = DIRECTORY_SEPARATOR; $ufolder = \Yii::getAlias('@app') . $ds . 'uploads' . $ds . 'temp' . $ds . $dirName . $ds; //директория откуда надо скопировать файлы if (file_exists($ufolder)) { $files = scandir($ufolder, 1); foreach ($files as $file) { //Get extension of file if ($file != '.' && $file != '..' && $file[0] != '.') { $parts = explode('.', $file); $ext = '.' . $parts[count($parts) - 1]; //расширение файла $new_folder = \Yii::getAlias('@app') . $ds . 'uploads' . $ds . 'stage' . $ds . 'files' . $ds . $this->id . $ds; //директория куда надо скопировать файлы if (!file_exists($new_folder)) { mkdir($new_folder, 0777); } $new_name = md5($file . time() . rand(0, 10000)) . $ext; rename($ufolder . $file, $new_folder . $new_name); $attachment = new Attachment(); $attachment->md5 = $new_name; $attachment->name = $file; $attachment->path = str_replace(\Yii::getAlias('@app'), '', \Yii::getAlias('@web') . $new_folder . $new_name); $attachment->item_id = $this->id; $attachment->save(); } } rmdir($ufolder); } }
public function getAttachments() { return $this->hasMany(Attachment::className(), ['document_id' => 'id']); }
/** * Remove the specified resource from storage. * * @param Services $services * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ public function destroy(Services $services) { $image = Attachment::where('id', $services->attachment_id); $services->delete(); $image->delete(); return redirect()->route('admin.services.index'); }
/** * Execute the job. * * @return bool */ public function handle() { $this->attachment->name = $this->request->input('name', $this->attachment->name); return $this->attachment->save(); }
public function actionDownload($id) { $model = $this->findModel(Attachment::className(), $id); $this->checkPermission($model); return $this->download($model->getPath()); }