/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = Input::get('new_name'); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } return 'OK'; }
/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = trim(Input::get('new_name')); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-alnum'); } elseif (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); Event::fire(new FolderWasRenamed($old_file, $new_file)); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } Event::fire(new ImageWasRenamed($old_file, $new_file)); return 'OK'; }
private function getFileInfos($files, $type = 'Images') { $file_info = []; foreach ($files as $key => $file) { $file_name = parent::getFileName($file)['short']; $file_created = filemtime($file); $file_size = number_format(File::size($file) / 1024, 2, ".", ""); if ($file_size > 1024) { $file_size = number_format($file_size / 1024, 2, ".", "") . " Mb"; } else { $file_size = $file_size . " Kb"; } if ($type === 'Images') { $file_type = File::mimeType($file); $icon = ''; } else { $extension = strtolower(File::extension($file_name)); $icon_array = Config::get('lfm.file_icon_array'); $type_array = Config::get('lfm.file_type_array'); if (array_key_exists($extension, $icon_array)) { $icon = $icon_array[$extension]; $file_type = $type_array[$extension]; } else { $icon = "fa-file"; $file_type = "File"; } } $file_info[$key] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'icon' => $icon]; } return $file_info; }
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(); } } }
public function postStore() { $id = Input::get('id'); /* * Validate */ $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required', 'short_description' => 'required', 'long_description' => 'required', 'start_date' => 'required', 'end_date' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->passes()) { $name = Input::get('name'); $short_description = Input::get('short_description'); $long_description = Input::get('long_description'); $image = Input::file('image'); $active = Input::get('active') == '' ? FALSE : TRUE; $cn_name = Input::get('cn_name'); $cn_short_description = Input::get('cn_short_description'); $cn_long_description = Input::get('cn_long_description'); $options = array('name' => $cn_name, 'short_description' => $cn_short_description, 'long_description' => $cn_long_description); $start_date = DateTime::createFromFormat('d/m/Y', Input::get('start_date')); $end_date = DateTime::createFromFormat('d/m/Y', Input::get('end_date')); $promotion = isset($id) ? Promotion::find($id) : new Promotion(); $promotion->name = $name; $promotion->start_date = $start_date; $promotion->end_date = $end_date; $promotion->short_description = $short_description; $promotion->long_description = $long_description; $promotion->active = $active; $promotion->options = json_encode($options); $promotion->save(); if (Input::hasFile('image')) { // Delete all existing images for edit if (isset($id)) { $promotion->deleteAllImages(); } //set the name of the file $originalFilename = $image->getClientOriginalName(); $filename = 'promo' . date("dmY") . '_' . Str::random(20) . '.' . File::extension($originalFilename); //Upload the file $isSuccess = $image->move('assets/img/promotions', $filename); if ($isSuccess) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $promotion->images()->save($newimage); } } } else { if (isset($id)) { return Redirect::to('admin/promotions/edit/' . $id)->withErrors($validation)->withInput(); } else { return Redirect::to('admin/promotions/create')->withErrors($validation)->withInput(); } } return Redirect::to('admin/promotions'); }
/** * 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')); }
/** * * Set proper header to serve the video content * */ private function setHeader() { ob_get_clean(); $extension = File::extension($this->path); if ($extension == 'ogg') { header("Content-Type: application/ogg"); } else { header("Content-Type: application/octet-stream"); } //header("Content-Type: application/octet-stream"); header("Cache-Control: max-age=2592000, public"); header("Expires: " . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT'); header("Last-Modified: " . gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT'); $this->start = 0; $this->size = filesize($this->path); $this->end = $this->size - 1; header("Accept-Ranges: 0-" . $this->end); if (isset($_SERVER['HTTP_RANGE'])) { $c_start = $this->start; $c_end = $this->end; list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); if (strpos($range, ',') !== false) { header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes {$this->start}-{$this->end}/{$this->size}"); exit; } if ($range == '-') { $c_start = $this->size - substr($range, 1); } else { $range = explode('-', $range); $c_start = $range[0]; $c_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $c_end; } $c_end = $c_end > $this->end ? $this->end : $c_end; if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) { header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes {$this->start}-{$this->end}/{$this->size}"); exit; } $this->start = $c_start; $this->end = $c_end; $length = $this->end - $this->start + 1; fseek($this->stream, $this->start); header('HTTP/1.1 206 Partial Content'); header("Content-Length: " . $length); header("Content-Range: bytes {$this->start}-{$this->end}/" . $this->size); } else { header("Content-Length: " . $this->size); } }
static function get($img, $w = "", $h = "", $crop = true, $params = array()) { $fullPath = public_path() . '/' . $img; if (!File::exists($fullPath)) { return false; } $format = ''; $width = ''; $htmlWidth = ''; $height = ''; $htmlHeight = ''; $filter = ""; $method = ''; $lazyParams = ''; $ext = File::extension($fullPath); if ($ext == 'png') { $firstBytes = @file_get_contents($fullPath, false, null, 25, 1); if (ord($firstBytes) & 4) { $format = "f=png"; //for transparent pngs } } if ($w) { $width = 'w=' . $w; $htmlWidth = 'width="' . $w . '"'; } if ($h) { $height = 'h=' . $h; $htmlHeight = 'height="' . $h . '"'; } if (count($params) > 0) { $filter = implode('&', $params); //eg: fltr[]=gray } if ($w != "" && $h != "") { if ($crop) { $method = 'zc=1'; } else { $method = 'far=1&bg=FFFFFF'; } } $image = 'src=' . $img; $optionsSlices = array($method, $width, $height, $filter, $image, $format); $options = implode('&', array_filter($optionsSlices)); $src = Url::to('/phpthumb') . "?" . $options; $htmlOptionsSlices = array($htmlWidth, $htmlHeight, $lazyParams); $htmlOptions = implode(' ', array_filter($htmlOptionsSlices)); return '<img src="' . $src . '" ' . $htmlOptions . ' />'; }
/** * @return string */ public function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . $this->file_location . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . $this->file_location . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); if (Session::get('lfm_type') == "Images") { // rename thumbnail File::move(base_path() . "/" . $this->file_location . "thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . "thumbs/" . $new_name); } return "OK"; } } } else { if (File::exists(base_path() . "/" . $this->file_location . $dir . "/" . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); if (Session::get('lfm_type') == "Images") { File::move(base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $new_name); } return "OK"; } } } return true; }
/** * @return string */ function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { // rename thumbnail File::move(base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } } } else { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); return "OK"; } } } }
/** * Return json list of files * * @return mixed */ public function getFiles() { if (Input::has('base')) { $files = File::files(base_path($this->file_location . Input::get('base'))); $all_directories = File::directories(base_path($this->file_location . Input::get('base'))); } else { $files = File::files(base_path($this->file_location)); $all_directories = File::directories(base_path($this->file_location)); } $directories = []; foreach ($all_directories as $directory) { $directories[] = basename($directory); } $file_info = []; $icon_array = Config::get('lfm.file_icon_array'); $type_array = Config::get('lfm.file_type_array'); foreach ($files as $file) { $file_name = $file; $file_size = 1; $extension = strtolower(File::extension($file_name)); if (array_key_exists($extension, $icon_array)) { $icon = $icon_array[$extension]; $type = $type_array[$extension]; } else { $icon = "fa-file"; $type = "File"; } $file_created = filemtime($file); $file_type = ''; $file_info[] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'extension' => $extension, 'icon' => $icon, 'type' => $type]; } if (Input::get('show_list') == 1) { return View::make('laravel-filemanager::files-list')->with('directories', $directories)->with('base', Input::get('base'))->with('file_info', $file_info)->with('dir_location', $this->file_location); } else { return View::make('laravel-filemanager::files')->with('files', $files)->with('directories', $directories)->with('base', Input::get('base'))->with('file_info', $file_info)->with('dir_location', $this->file_location); } }
/** * Scan files of the given directory. * * @param $current_directory * @return \Illuminate\Support\Collection */ protected function scanFiles($current_directory) { $files = collect($this->storage->files($current_directory)); $files = $files->filter(function ($file) { $ext = File::extension($file); if ($this->filter === 'images') { return in_array($ext, $this->config->get('media.images_ext')); } elseif ($this->filter === 'files') { return in_array($ext, $this->config->get('media.files_ext')); } return true; }); return $files; }
<?php use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\File; use Swagger\Swagger; $app->get(config('swagger-lume.routes.docs'), function ($page = 'api-docs.json') { $filePath = config('swagger-lume.paths.docs') . "/{$page}"; if (File::extension($filePath) === '') { $filePath .= '.json'; } if (!File::exists($filePath)) { App::abort(404, "Cannot find {$filePath}"); } $content = File::get($filePath); return new Response($content, 200, ['Content-Type' => 'application/json']); }); $app->get(config('swagger-lume.routes.api'), function () { if (config('swagger-lume.generate_always')) { \SwaggerLume\Generator::generateDocs(); } if (config('swagger-lume.proxy')) { $proxy = (new Request())->server('REMOTE_ADDR'); (new Request())->setTrustedProxies([$proxy]); } $extras = []; $conf = config('swagger-lume'); if (array_key_exists('validatorUrl', $conf)) { // This allows for a null value, since this has potentially // desirable side effects for swagger. See the view for more
/** * Return the type of the resource * * @param string $path */ public function extension($path) { return File::extension($this->getPath($path)); }
public function download(Fileentry $entry) { $extension = File::extension($entry->link); $password = file_get_contents('../filepassword'); Request::get('pass'); if ($password == Request::get('pass')) { if (!Auth::user()) { $entry->increment('views'); } return response()->download($entry->link, $entry->title . '.' . $extension); } else { return redirect("documents")->withErrors(['pnm' => ""]); } }
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; }
/** * @return string */ public function info() { $filename = $this->getFullPath(); if (!$this->exists()) { return ''; } $extension = IlluminateFile::extension($filename); return strtr(static::TEMPLATE_INFO, [':type' => $extension]); }
/** * Merge multiple pdf documents together * @arg 1st is name of output file * @arg All others are input files */ public function merge() { $args = func_get_args(); $output = array_shift($args); if (isset($args[0]) && $args[0] && is_array($args[0])) { $pdfs = $args[0]; } else { $pdfs = $args; } foreach ($pdfs as $pdf) { if (!strtolower(File::extension($pdf)) == 'pdf') { throw new \Exception('Tous les documents doivent être dans le format PDF'); } } $pdfs = implode(' ', $pdfs); $command = 'pdftk ' . $pdfs . ' cat output ' . $output; shell_exec($command); }
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); }
/** * Check if a file is a raster image based on the extension. * * @param string $file * @return boolean */ public function isRasterImage($file = '') { return in_array(strtolower(File::extension($file)), $this->imageExtensions); }
/** * @param $findResults * @param $directory * @param $fileNameWithoutExt * @param $imagePattern * @param $row * @param $createdProductCategories */ private function createProductCategory($findResults, $directory, $fileNameWithoutExt, $imagePattern, $row, $createdProductCategories) { $imageOriginalPath = $findResults[0]; $imageExt = File::extension($imageOriginalPath); $imagePath = $directory . $fileNameWithoutExt . $imagePattern . '.' . $imageExt; $newImagePath = 'img/uploads/' . str_random(32) . '.' . $imageExt; File::move($imagePath, public_path() . '/' . $newImagePath); $createdProductCategories[$row['nomer']] = ProductCategory::create(['title' => $row['nazvanie'], 'image' => $newImagePath, 'description' => $row['opisanie']]); }
private function upload_image() { /* validate the image */ $validation = Validator::make($this->image, array($this->input => $this->rules)); $errors = array(); $original_name = $this->image[$this->input]->getClientOriginalName(); $path = ''; $filename = ''; $resizes = ''; if ($validation->fails()) { /* use the messages object for the erros */ $errors = implode('. ', $validation->messages()->all()); } else { if ($this->random) { if (is_callable($this->random_cb)) { $filename = call_user_func($this->random_cb, $original_name); } else { $ext = File::extension($original_name); $filename = $this->generate_random_filename() . '.' . $ext; } } else { $filename = $original_name; } /* upload the file */ $save = $this->image[$this->input]->move($this->path, $filename); //$save = Input::upload($this->input, $this->path, $filename); if ($save) { $path = $this->path . $filename; if (is_array($this->image_sizes)) { $resizer = new Resize(); $resizes = $resizer->create($save, $this->path, $filename, $this->image_sizes); } } else { $errors = 'Could not save image'; } } return compact('errors', 'path', 'filename', 'original_name', 'resizes'); }
/** * Resizes and/or crops an image * @param mixed $image resource or filepath * @param strung $save_path where to save the resized image * @param int (0-100) $quality * @return bool */ private function do_resize($image, $save_path, $image_quality) { $image = $this->open_image($image); $this->width = imagesx($image); $this->height = imagesy($image); // Get optimal width and height - based on $option. $option_array = $this->get_dimensions($this->new_width, $this->new_height, $this->option); $optimal_width = $option_array['optimal_width']; $optimal_height = $option_array['optimal_height']; // Resample - create image canvas of x, y size. $this->image_resized = imagecreatetruecolor($optimal_width, $optimal_height); // Retain transparency for PNG and GIF files. imagecolortransparent($this->image_resized, imagecolorallocatealpha($this->image_resized, 255, 255, 255, 127)); imagealphablending($this->image_resized, false); imagesavealpha($this->image_resized, true); // Create the new image. imagecopyresampled($this->image_resized, $image, 0, 0, 0, 0, $optimal_width, $optimal_height, $this->width, $this->height); // if option is 'crop' or 'fit', then crop too if ($this->option == 'crop' || $this->option == 'fit') { $this->crop($optimal_width, $optimal_height, $this->new_width, $this->new_height); } // Get extension of the output file $extension = strtolower(File::extension($save_path)); // Create and save an image based on it's extension switch ($extension) { case 'jpg': case 'jpeg': if (imagetypes() & IMG_JPG) { imagejpeg($this->image_resized, $save_path, $image_quality); } break; case 'gif': if (imagetypes() & IMG_GIF) { imagegif($this->image_resized, $save_path); } break; case 'png': // Scale quality from 0-100 to 0-9 $scale_quality = round($image_quality / 100 * 9); // Invert quality setting as 0 is best, not 9 $invert_scale_quality = 9 - $scale_quality; if (imagetypes() & IMG_PNG) { imagepng($this->image_resized, $save_path, $invert_scale_quality); } break; default: return false; break; } // Remove the resource for the resized image imagedestroy($this->image_resized); return true; }
public function info() : string { return ($filename = $this->resolvePath()) ? strtr(static::TEMPLATE_INFO, [':type' => IlluminateFile::extension($filename), ':size' => round(IlluminateFile::size($filename) / 1000, 2) . ' Kb']) : ''; }
public function postStore() { $id = Input::get('id'); /* * Validate */ $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required|unique:products,name' . (isset($id) ? ',' . $id : ''), 'short_description' => 'required', 'price' => 'numeric', 'sku' => 'required|alpha_dash|unique:products,sku' . (isset($id) ? ',' . $id : ''), 'category_id' => 'required', 'tags' => 'regex:/^[a-z,0-9 -]+$/i'); $validation = Validator::make(Input::all(), $rules); if ($validation->passes()) { $name = Input::get('name'); $sku = Input::get('sku'); $price = Input::get('price'); $short_description = Input::get('short_description'); $long_description = Input::get('long_description'); $image = Input::file('image'); $featured = Input::get('featured') == '' ? FALSE : TRUE; $active = Input::get('active') == '' ? FALSE : TRUE; $category_id = Input::get('category_id'); $tags = Input::get('tags'); $cn_name = Input::get('cn_name'); $cn_short_description = Input::get('cn_short_description'); $cn_long_description = Input::get('cn_long_description'); $options = array('name' => $cn_name, 'short_description' => $cn_short_description, 'long_description' => $cn_long_description); $product = isset($id) ? Product::find($id) : new Product(); $product->name = $name; $product->sku = $sku; $product->price = isset($price) ? $price : 0; $product->short_description = $short_description; $product->long_description = $long_description; $product->featured = $featured; $product->active = $active; $product->category_id = $category_id; $product->options = json_encode($options); $product->save(); if (!empty($tags)) { // Delete old tags $product->deleteAllTags(); // Save tags foreach (explode(',', $tags) as $tagName) { $newTag = new Tag(); $newTag->name = strtolower($tagName); $product->tags()->save($newTag); } } if (Input::hasFile('image')) { // Delete all existing images for edit if (isset($id)) { $product->deleteAllImages(); } //set the name of the file $originalFilename = $image->getClientOriginalName(); $filename = $sku . Str::random(20) . '.' . File::extension($originalFilename); //Upload the file $isSuccess = $image->move('assets/img/products', $filename); if ($isSuccess) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $product->images()->save($newimage); } } } else { if (isset($id)) { return Redirect::to('admin/products/edit/' . $id)->withErrors($validation)->withInput(); } else { return Redirect::to('admin/products/create')->withErrors($validation)->withInput(); } } return Redirect::to('admin/products'); }
/** * Función para mover ficheros * * @access public * @param $path * @param $target * @param $fileName * @param bool $encryption * @param bool $newFilename * @return bool */ public static function move($path, $target, $fileName, $encryption = false, $newFilename = false) { $fileNameOld = $fileName; $extension = File::extension($fileName); $baseName = basename($fileName, '.' . $extension); if ($encryption) { mt_srand(); $fileName = md5(uniqid(mt_rand())) . "." . $extension; } elseif ($newFilename) { $fileName = $newFilename . "." . $extension; } $i = 0; while (File::exists($target . '/' . $fileName)) { $i++; $fileName = $baseName . '-' . $i . '.' . $extension; } File::move($path . '/' . $fileNameOld, $target . '/' . $fileName); return $fileName; }
/** * Big Upload * ini adalah upload menggunakan metode chuck * dengan ajax file */ public function bigUploads() { $bigUpload = new BigUpload(); $folder = $this->uploadfile->getUploadFolder(); $bigUpload->setTempDirectory(public_path('/videos/tmp')); $bigUpload->setMainDirectory($folder); $bigUpload->setTempName(Input::get('key', null)); switch (Input::get('action')) { case 'upload': return $bigUpload->uploadFile(); break; case 'abort': return $bigUpload->abortUpload(); break; case 'finish': $rand = Str::random(10); $randomname = $rand . '.' . Input::get('ext'); $finish = $bigUpload->finishUpload($randomname); if (0 === $finish['errorStatus']) { // Create a new order if not exist if (null === $this->model) { $this->model = $this->repository->getModel()->newInstance(); /* //shell_exec("ffmpegthumbnailer -i " . $folder. $randomname ." -o ". static::$app['path.base']."/public/covers/" . $rand . ".png -s 400"); shell_exec("ffmpeg -itsoffset -5 -i ". $folder. $randomname ." -vcodec mjpeg -vframes 5 -an -f rawvideo ".static::$app['path.base']."/public/covers/" . $rand . ".jpg"); //Sonus::convert()->input( $folder. $randomname )->output(static::$app['path.base'].'/public/streams/' . $randomname )->go(); $resolusi = $this->__get_video_dimensions($folder.$randomname); if($resolusi['height'] >= 720){ shell_exec("ffmpeg -i {$folder}{$randomname} -s 960x720 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_720.mp4"); } shell_exec("ffmpeg -i {$folder}{$randomname} -s 480×360 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_360.mp4"); */ // File extension $this->model->code = $rand; $this->model->extension = File::extension($folder . $randomname); $this->model->mimetype = File::type($folder . $randomname); $this->model->owner_id = $this->ownerId; $this->model->size = File::size($folder . $randomname); $this->model->path = $this->uploadfile->cleanPath(static::$app['config']->get('video.upload_folder_public_path')) . $this->uploadfile->dateFolderPath; $this->model->filename = $randomname; $this->model->playback = $randomname; $this->model->cover = $rand . '.png'; $this->model->save(); if (null !== $this->model) { $info = $this->infoRepository->getModel()->where('video_id', $this->model->getId())->first(); // Create a new item $info = $info ? $info : $this->infoRepository->getModel()->newInstance(); $info->fill(array_merge(array('name' => Input::get('name')), array('video_id' => $this->model->getId()))); if (!$info->save()) { throw new Exception("Could not create a video info"); } } } return array('errorStatus' => 0, 'id' => $this->model->getId(), 'code' => $this->model->code); } return $finish; break; case 'post-unsupported': //return $bigUpload->postUnsupported(); return $this->upload(Input::file('bigUploadFile')); break; } }
public function insert($file_path, $attributes = []) { if (!File::exists($file_path)) { return -1; } DB::beginTransaction(); try { $extension = File::extension($file_path); $filenameWithoutExtension = $this->filenameWithoutExtension(); $filename = $this->filename($filenameWithoutExtension, $extension); $size = File::size($file_path); $save_dir = $this->filePath($this->_dir); if (!File::exists($save_dir)) { File::makeDirectory($save_dir); } $save_path = $save_dir . '/' . $filename; File::copy($file_path, $save_path); DB::commit(); } catch (Exception $e) { DB::rollback(); return -1; } return $this->saveData($filename, $extension, $size, $attributes); }
/** * Create a unique string for a table field. You may optionally limit the number of characters. * * @param string $string * @param string $table * @param string $fieldName * @param mixed $ignoreId * @param boolean $filename * @param mixed $charLimit * @return mixed */ public function unique($string, $table, $fieldName = 'name', $ignoreId = false, $filename = false, $charLimit = false) { if ($ignoreId) { $exists = DB::table($table)->where($fieldName, '=', $string)->where('id', '!=', $ignoreId)->count(); } else { $exists = DB::table($table)->where($fieldName, '=', $string)->count(); } $extension = $filename ? File::extension($string) : ''; if ((int) $exists) { $uniqueFound = false; if ($charLimit) { $string = substr($string, 0, $charLimit - 2); } $originalString = $string; for ($s = 2; $s <= 99; $s++) { if (!$uniqueFound) { $string = $originalString; $suffix = '-' . $s; if ($filename) { $string = str_replace('.' . $extension, '', $string) . $suffix . '.' . $extension; } else { $string .= $suffix; } if ($ignoreId) { $exists = DB::table($table)->where($fieldName, '=', $string)->where('id', '!=', $ignoreId)->count(); } else { $exists = DB::table($table)->where($fieldName, '=', $string)->count(); } if (!$exists) { $uniqueFound = true; } } } if (!$uniqueFound) { return false; } } return $string; }
/** * * Check if all the parts exist, and * gather all the parts of the file together * @param string $dir - the temporary directory holding all the parts of the file * @param string $fileName - the original file name * @param string $chunkSize - each chunk size (in bytes) * @param string $totalSize - original file size (in bytes) */ function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize) { // count all the parts of this file $total_files = 0; foreach (scandir($temp_dir) as $file) { if (stripos($file, $fileName) !== false) { $total_files++; } } // check that all the parts are present // the size of the last part is between chunkSize and 2*$chunkSize if ($total_files * $chunkSize >= $totalSize - $chunkSize + 1) { // create the final destination file if (($fp = fopen($this->mainDirectory . $fileName, 'w')) !== false) { for ($i = 1; $i <= $total_files; $i++) { fwrite($fp, file_get_contents($temp_dir . '/' . $fileName . '.part' . $i)); $this->_log($fileName . ' writing chunk ' . $i); } fclose($fp); //set return fileinfo $this->fileinfo = array('filename' => $fileName, 'extension' => File::extension($this->mainDirectory . $fileName), 'size' => File::size($this->mainDirectory . $fileName)); } else { $this->_log('cannot create the destination file'); return false; } // rename the temporary directory (to avoid access from other // concurrent chunks uploads) and than delete it if (rename($temp_dir, $temp_dir . '_UNUSED')) { $this->rrmdir($temp_dir . '_UNUSED'); } else { $this->rrmdir($temp_dir); } } }