public static function store($files, $material) { // Making counting of uploaded images $file_count = count($files); // start count how many uploaded $uploadcount = 0; if (!empty($files)) { foreach ($files as $file_path) { if (!empty($file_path)) { $type = File::type($file_path); $mime = File::mimeType($file_path); $extension = File::extension($file_path); $filename = $material->slug . '_' . str_replace(' ', '_', File::name($file_path)) . '.' . $extension; File::move($file_path, storage_path() . '/app/' . $filename); //add file path and thumb path to material_files database $material_file = MaterialFile::firstOrCreate(['original_filename' => File::name($file_path), 'filename' => $filename, 'mime' => $mime]); //add to material file table $material->files()->save($material_file); $uploadcount++; //create thumb MaterialFile::makeThumb($extension, $filename); } } if ($uploadcount == $file_count) { Session::flash('success', 'Upload(s) successfully'); } else { return Redirect::to('material.edit')->withInput(); } } }
/** * Display the specified resource. * * @param string $name * @return Response */ public function show($name) { $project = Project::where('name', $name)->get()->first(); $x = new Filesystem(); $filesDestination = File::allfiles($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $name); $files = array(); for ($c = 0; $c < count($filesDestination); $c++) { $files[$c] = File::name($filesDestination[$c]) . '.' . File::extension($filesDestination[$c]); } //dd($filenames); return view('project.show', compact('project', 'files')); }
private function getAndMake($files) { foreach ($files as $file) { if (strpos($file, 'thumb_') === false) { $content = Storage::disk('s3')->get($file); $name = File::name($file); $destination = base_path() . "/storage/{$name}.png"; File::put($destination, $content); Log::info("Convert {$file} {$destination}"); $thumb_destination = $this->thumbnail_destination . "/thumb_{$name}.gif"; Log::info($thumb_destination); if (!File::exists($thumb_destination)) { exec("convert -define png:size=387x500 {$destination} -auto-orient -thumbnail 387x500 -unsharp 0x.5 {$thumb_destination}", $output, $results); } } } }
public function url($filename, $dir = null) { $this->results['filename'] = $filename; $this->results['path'] = rtrim($this->uploadpath, '/') . ($dir ? '/' . trim($dir, '/') : ''); $this->results['dir'] = str_replace(public_path() . '/', '', $this->results['path']); $this->results['filename'] = $filename; $this->results['filepath'] = rtrim($this->results['path']) . '/' . $this->results['filename']; if (File::exists($this->results['filepath'])) { $this->results['filedir'] = str_replace(public_path() . '/', '', $this->results['filepath']); $this->results['basename'] = File::name($this->results['filepath']); $this->results['filesize'] = File::size($this->results['filepath']); $this->results['extension'] = File::extension($this->results['filepath']); $this->results['mime'] = File::mimeType($this->results['filepath']); if ($this->isImage($this->results['mime'])) { list($width, $height) = getimagesize($this->results['filepath']); $this->results['width'] = $width; $this->results['height'] = $height; if (!empty($this->dimensions) && is_array($this->dimensions)) { foreach ($this->dimensions as $name => $dimension) { $suffix = trim($name); $path = $this->results['path'] . ($this->suffix == false ? '/' . trim($suffix, '/') : ''); $name = $this->results['basename'] . ($this->suffix == true ? '_' . trim($suffix, '/') : '') . '.' . $this->results['extension']; $pathname = $path . '/' . $name; if (File::exists($pathname)) { list($nwidth, $nheight) = getimagesize($pathname); $filesize = File::size($pathname); $this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => $pathname, 'filedir' => str_replace(public_path() . '/', '', $pathname), 'width' => $nwidth, 'height' => $nheight, 'filesize' => $filesize]; } else { $this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => '#', 'filedir' => '#']; } } } } return new Collection($this->results); } return null; }
public function delete_attachment($file_name, $entity = 'event', $entity_id = 0, $type = NULL) { $path = $entity . '/' . $entity_id . '/'; switch ($type) { case 'group_photo': $file_name = 'group_photo.jpg'; $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_GROUP_PHOTO)->firstOrFail(); $path = $entity . '/' . $entity_id . '/'; $updated_file_name = 'group_photo-deleted-' . time() . '.jpg'; break; case 'contract': $file_name = 'contract.pdf'; $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_CONTRACT_PHOTO)->firstOrFail(); $path = $entity . '/' . $entity_id . '/'; $updated_file_name = 'contract-deleted-' . time() . '.pdf'; break; case 'schedule': $file_name = 'schedule.pdf'; $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_CONTRACT)->firstOrFail(); $path = $entity . '/' . $entity_id . '/'; $updated_file_name = 'schedule-deleted-' . time() . '.pdf'; break; case 'evaluations': $file_name = 'evaluations.pdf'; $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_EVENT_EVALUATION)->firstOrFail(); $path = $entity . '/' . $entity_id . '/'; $updated_file_name = 'evaluations-deleted-' . time() . '.pdf'; break; case 'attachment': $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_CONTACT_ATTACHMENT)->firstOrFail(); $path = $entity . '/' . $entity_id . '/attachments/'; $file_extension = File::extension($path . $file_name); $file_basename = File::name($path . $file_name); $updated_file_name = $file_basename . '-deleted-' . time() . '.' . $file_extension; break; case 'avatar': $attachment = \montserrat\Attachment::whereEntity($entity)->whereEntityId($entity_id)->whereUri($file_name)->whereFileTypeId(FILE_TYPE_CONTACT_AVATAR)->firstOrFail(); $path = $entity . '/' . $entity_id . '/'; $updated_file_name = 'avatar-deleted-' . time() . '.png'; break; default: break; } if (!File::exists(storage_path() . '/app/' . $path . $file_name)) { abort(404); } if (Storage::move($path . $file_name, $path . $updated_file_name)) { $attachment->uri = $updated_file_name; $attachment->save(); $attachment->delete(); } return Redirect::action('RetreatsController@show', $entity_id); }
public function put(File $file) { $response = $this->client->put('/' . $file->name(), ['body' => $file->get()]); return trim($response->getBody()->getContents()); }
/** * List templates files from directory. * * @return array */ public function templates() { try { $directory = $this->getTemplateDir(); $files = File::files($directory); } catch (Exception $e) { $files = File::files(base_path('vendor/typicms/pages/src/resources/views/public')); } $templates = []; foreach ($files as $file) { $filename = File::name($file); $name = str_replace('.blade', '', $filename); if ($name[0] != '_' && $name != 'master') { $templates[$name] = ucfirst($name); } } return ['' => ''] + $templates; }