/** * Delete file * */ protected function deleteFile($id) { $f = \Veer\Models\Download::find($id); if (!is_object($f)) { return false; } $allCopies = \Veer\Models\Download::where('fname', '=', $f->fname)->get(); if (count($allCopies) <= 1) { // last one $this->deletingLocalOrCloudFiles('files', $f->fname, config("veer.downloads_path"), storage_path() . '/app/'); } $f->delete(); return true; }
public function mklink($id = null, $data = null, $returnId = false) { if (empty($id) && !isset($this->entity->id)) { return $this; } elseif (empty($id)) { $id = $this->entity->id; } $data = (array) $data; $data += ['times' => 0, 'expiration_day' => null, 'link_name' => null]; $file = is_object($this->entity) ? $this->entity : \Veer\Models\Download::find($id); if (!is_object($file)) { return $this; } $new = $file->replicate(); $new->secret = empty($data['link_name']) ? bcrypt(str_random(100) . date("Ymd", time())) : $data['link_name']; // @todo test if ($data['times'] > 0 || !empty($data['expiration_day'])) { $new->expires = 1; $new->expiration_times = $data['times']; if (!empty($data['expiration_day'])) { $new->expiration_day = \Carbon\Carbon::parse(strtotime($data['expiration_day'])); } } $new->original = 0; $new->save(); event('veer.message.center', trans('veeradmin.file.download')); return $returnId ? $new->id : $this; }