public function create(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $projectFile = $this->repository->skipPresenter()->create($data); $this->storage->put($projectFile->getFileName(), $this->filesystem->get($data['file'])); return ['success' => true]; } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag(), "messageDev" => 'ValidatorException']; } catch (\Exception $e) { return ["error" => true, "message" => 'Falha ao gravar registro.', "messageDev" => $e->getMessage()]; } }
/** * Upload to Local or Cloud * */ protected function uploadingLocalOrCloudFiles($type, $file, $fname, $assetPath, $localDestination = "") { if (!config('veer.use_cloud_' . $type)) { return $file->move($localDestination . $assetPath, $fname); } \Storage::put($assetPath . '/' . $fname, file_get_contents($file->getPathName())); }
/** * Run the database seeds. * * @return void */ public function run() { // Suppression préalable des fichiers de upload par l'utilisation de la variable storage définie à l'aide de l'instruction public_path('upload') du fichier de configuration config\filesystem.php) $files = Storage::allFiles(); //retroune un tableau des images de storage foreach ($files as $file) { Storage::delete($file); } //Supprimer toutes les lignes de la talble Pictures // DB::table('pictures')-> // Récupération d'un faker opétationnel // $faker = Faker\Factory::create(); $products = Product::all(); foreach ($products as $product) { // Stokage de l'image et récupération de l'uri $uri = str_random(15) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/people/370/325/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } // DB::table('pictures')->insert( // [ // [ // 'product_id' => '2' , // 'uri' => $uri // ], // ] // ); }
/** * process request from gitlab webhook. * * @param Request $request * @return Response */ public function hookHandler(Request $request) { $clientIp = !empty($request->header('X-Forwarded-For')) ?: $request->ip(); Log::debug('hook received from ' . $clientIp); if ($this->isVerbose()) { dump($request); } $eventType = $request->headers->get('X-Gitlab-Event'); if (is_null($eventType)) { $eventType = 'Push Hook'; } // for debugging purpose. \Storage::put(str_replace(' ', '-', $eventType) . ".json", json_encode($request->json()->all(), JSON_PRETTY_PRINT)); Log::info('eventType : ' . $eventType); if ($eventType == 'Push Hook') { return $this->pushHook($request); } elseif ($eventType == 'Tag Push Hook') { return $this->tagPushHook($request); } elseif ($eventType == 'Issue Hook') { return $this->issueHook($request); } elseif ($eventType == 'Note Hook') { return $this->noteHook($request); } elseif ($eventType == 'Merge Request Hook') { return $this->mergeRequestHook($request); } abort(500, 'Unknown Hook type : ' . $eventType); }
public function createFile(array $data) { $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $arquivo = $projectFile->id . "." . $data['extension']; \Storage::put($arquivo, \File::get($data['file'])); }
public function creating(Media $media) { $uploadedFile = $this->request->file('media'); $fileName = time() . $uploadedFile->getClientOriginalName(); \Storage::put($fileName, file_get_contents($uploadedFile->getRealPath())); $media->url = url('uploads/' . $fileName); }
* @access protected * @param string $templateFile 指定要调用的模板文件 * 默认为空 由系统自动定位模板文件 * @param string $charset 输出编码 * @param string $contentType 输出类型 * @param string $content 输出内容 * @param string $prefix 模板缓存前缀 * @return void */
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->hasFile('file')) { $name = $request->file('file')->getClientOriginalName(); \Storage::put($name, file_get_contents($request->file('file')->getRealPath())); return response()->json(['img' => $name]); } }
public function imageresponse($name) { $randomcolor = RandomColor::one(array('luminosity' => 'light')); $img = \DefaultProfileImage::create($name, 256, $randomcolor, '#FFF'); \Storage::put("profile.png", $img->encode()); $headers = ['Content-Type' => 'image/jpeg', 'Content-Disposition' => 'inline', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public']; return \Response::make($img, 200, $headers)->setTtl(60 * 30); }
public function testDelete() { Storage::put('test-file.txt', 'what is this'); $file = factory(\Yab\Quarx\Models\File::class)->make(['id' => 2, 'location' => ['file_a' => ['name' => CryptoService::encrypt('test-file.txt'), 'original' => 'test-file.txt', 'mime' => 'txt', 'size' => 24]]]); $this->call('POST', 'quarx/files', $file->getAttributes()); $response = $this->call('DELETE', 'quarx/files/2'); $this->assertEquals(302, $response->getStatusCode()); $this->assertRedirectedTo('quarx/files'); }
function postAdd() { $data = json_decode(\File::get(storage_path() . '/app/data.json'), 1); $product = ['name' => \Input::get('product_name'), 'quantity' => \Input::get('quantity'), 'price' => \Input::get('price'), 'timestamp' => date("Y-m-d H:i:s")]; $data[] = $product; \Storage::put('data.json', json_encode($data)); $product['timestamp'] = date("m/d/Y h:i a", strtotime($product['timestamp'])); return \Response::json(['success' => true, 'data' => $product]); }
/** * Upload a single image * @param $file Object * @param $path String * @return String Image name */ private function makeUpload($file, $path) { // Get file name $filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); // Create safe name with extension $name = str_slug($filename) . '.' . $file->getClientOriginalExtension(); // Upload \Storage::put($path . $name, file_get_contents($file->getRealPath())); return $name; }
/** * Store the new game in the database * * @param App\Http\Requests\StoreGameRequest $request * @param App\Repositories\GameRepository $gameRepo * * @return response */ public function store(StoreGameRequest $request, GameRepository $gameRepo) { $game = $gameRepo->create($request); if ($request->hasFile('image') and $request->file('image')->isValid()) { $imageUri = 'games/logos/' . $game->id . '_logo_' . \Carbon\Carbon::now()->timestamp . '.' . $request->file('image')->getClientOriginalExtension(); \Storage::put($imageUri, file_get_contents($request->file('image')->getRealPath())); $game->logo = $imageUri; $game->save(); } return redirect()->route('admin.games.index')->with('success', $game->name . " has been created"); }
/** * rollback */ public function rollback() { $this->storage->remove($this->uri, $this->options); if (is_null($this->previous)) { $this->storage->remove($this->uri); } else { $this->storage->put($this->previous, $this->uri, $this->options); } $this->clean(); $this->initialize(); }
/** * @covers mychaelstyle\Storage::put */ public function testPut() { $def1 = $this->dsnMap['Local']; $def2 = $this->dsnMap['Local2']; $this->object->addProvider($def2['dsn'], $def2['options']); $path = DIR_FIXTURES . '/example.txt'; $expected = file_get_contents($path); $this->object->put($path, $this->uri_example, array('permission' => 0644)); $this->assertLocalWritten($def1['dsn'], $expected, $this->uri_example); $this->assertLocalWritten($def2['dsn'], $expected, $this->uri_example); }
/** * Execute the console command. * * @return mixed */ public function handle() { $tables = ['maven_faqs', 'maven_tags', 'maven_unique_keys']; foreach ($tables as $table) { $values = \DB::table($table)->get(); if (count($values)) { $json = json_encode($values); \Storage::put('maven/' . $table . '.json', $json); $this->info('"' . $table . '" exported!'); } } }
public function createUserList() { // fetch users list from gitlab and create file. $client = new HttpClient(); $body = $client->getAllUsers(); $users = []; foreach ($body as $u) { $users[$u->id] = ['name' => $u->name, 'username' => $u->username, 'state' => $u->state]; } \Storage::put($this->userList, json_encode($users, JSON_PRETTY_PRINT)); return $users; }
public function pub_img($msg) { $user = Login::where('wxuin', $this->wxuin)->where('status', 1)->first(); if (!$user) { $this->death(); } $cookies = json_decode($user->cookies); $url = "https://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?MsgID=" . $msg['MsgId'] . "&skey=" . urlencode($user->skey) . "&__r=-" . t(); $img = CURL::send($url, ['Cookie' => urldecode(http_build_query($cookies, '', '; '))], [], ['ret' => 'body']); \Storage::put('img/' . $msg['MsgId'] . ".jpg", $img); echo "put_img: img/" . $msg['MsgId'] . ".jpg\r\n"; return '已接收到图片'; }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $test = Product::all(); foreach ($test as $value) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235')); Picture::create(['product_id' => $value->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $products = App\Product::all(); foreach ($products as $product) { // pour importer de fichiers distants $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
public function getCityByCountry($countryCode) { $file = 'city_list_' . $countryCode; if (!\Storage::has('location/' . $file)) { $data = json_encode(\DB::table($this->cityTable)->where('countryCode', $countryCode)->orderBy('name', 'asc')->get()); \Storage::put('location/' . $file, $data); return $data; } else { try { $city = \Storage::get('location/' . $file); return $city; } catch (\Exception $e) { return $e->getMessage(); } } }
/** * Run the database seeds. * * @return void */ public function run() { // Eloquent::unguard(); DB::table('pictures')->delete(); DB::statement("ALTER TABLE pictures AUTO_INCREMENT=1"); $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->facker->name, 'type' => 'jpg', 'size' => 200]); } }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); //sert a vider le dossier upload si on relance un refresh //pour éviter de stocker 15 images + 15 images ect... } $products = Product::all(); //recupere tous les produits precedement creer dans un tableau foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; //str_random fait un chaine de caractere de 12 Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->insert([['name' => 'Tony', 'email' => '*****@*****.**', 'password' => Hash::make('Tony'), 'role' => 'administrator'], ['name' => 'Antoine', 'email' => '*****@*****.**', 'password' => Hash::make('Antoine'), 'role' => 'visitor'], ['name' => 'Romain', 'email' => '*****@*****.**', 'password' => Hash::make('Tony'), 'role' => 'visitor'], ['name' => 'yini', 'email' => '*****@*****.**', 'password' => Hash::make('Yini'), 'role' => 'visitor']]); factory(App\Customer::class, 4)->create(); // avatars DB::table('avatars')->delete(); DB::statement("ALTER TABLE avatars AUTO_INCREMENT=1"); $files = Storage::allFiles(env('UPLOADS_AVATARS', 'uploads')); foreach ($files as $file) { Storage::delete($file); } $users = User::all(); foreach ($users as $user) { $uri = str_random(12) . '_216x256.jpg'; $fileName = file_get_contents('http://lorempixel.com/216/256/animals'); $pathDirectory = env('UPLOADS_AVATARS', 'avatars') . DIRECTORY_SEPARATOR . $uri; Storage::put($pathDirectory, $fileName); $mime = mime_content_type(storage_path('app') . DIRECTORY_SEPARATOR . $pathDirectory); Avatar::create(['user_id' => $user->id, 'uri' => $uri, 'title' => $this->facker->name, 'mime' => $mime]); } }
public static function Init() { Core::PreProcess(); include_once 'classes/Api.class.php'; Api::fastInclude( CLASSPATH ); Api::fastInclude( CUSTOMPATH ); Api::fastInit(); Storage::put("Template::cssInclude", "<link rel=\"stylesheet\" href=\"{PATH}\" type=\"text/css\" media=\"all\" />\n"); Storage::put("Template::jsInclude", "<script type=\"text/javascript\" src=\"{PATH}\"></script>\n"); Template::configure( TEMPLATEPATH ); $url = "mysql:host=".Config::$DBConf["host"].";dbname=".Config::$DBConf["name"]; DB::setup($url, Config::$DBConf["user"], Config::$DBConf["pass"]); }
/** * 应用程序初始化 * @access public * @return void */ public static function start() { // 注册AUTOLOAD方法 spl_autoload_register('Think\\Think::autoload'); // 设定错误和异常处理 register_shutdown_function('Think\\Think::fatalError'); set_error_handler('Think\\Think::appError'); set_exception_handler('Think\\Think::appException'); // 初始化文件存储方式 Storage::connect(STORAGE_TYPE); $runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php'; if (!APP_DEBUG && Storage::has($runtimefile)) { Storage::load($runtimefile); } else { if (Storage::has($runtimefile)) { Storage::unlink($runtimefile); } $content = ''; // 读取应用模式 $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php'); // 加载核心文件 foreach ($mode['core'] as $file) { if (is_file($file)) { include $file; if (!APP_DEBUG) { $content .= compile($file); } } } // 加载应用模式配置文件 foreach ($mode['config'] as $key => $file) { is_numeric($key) ? C(include $file) : C($key, include $file); } // 读取当前应用模式对应的配置文件 if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . '.php')) { C(include CONF_PATH . 'config_' . APP_MODE . '.php'); } // 加载模式别名定义 if (isset($mode['alias'])) { self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias'])); } // 加载应用别名定义文件 if (is_file(CONF_PATH . 'alias.php')) { self::addMap(include CONF_PATH . 'alias.php'); } // 加载模式行为定义 if (isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags'])); } // 加载应用行为定义 if (is_file(CONF_PATH . 'tags.php')) { // 允许应用增加开发模式配置定义 Hook::import(include CONF_PATH . 'tags.php'); } // 加载框架底层语言包 L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php'); if (!APP_DEBUG) { $content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");"; $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}'; Storage::put($runtimefile, strip_whitespace('<?php ' . $content)); } else { // 调试模式加载系统默认的配置文件 C(include THINK_PATH . 'Conf/debug.php'); // 读取应用调试配置文件 if (is_file(CONF_PATH . 'debug.php')) { C(include CONF_PATH . 'debug.php'); } } } // 读取当前应用状态对应的配置文件 if (APP_STATUS && is_file(CONF_PATH . APP_STATUS . '.php')) { C(include CONF_PATH . APP_STATUS . '.php'); } // 设置系统时区 date_default_timezone_set(C('DEFAULT_TIMEZONE')); // 检查应用目录结构 如果不存在则自动创建 if (C('CHECK_APP_DIR') && !is_dir(LOG_PATH)) { // 创建应用目录结构 require THINK_PATH . 'Common/build.php'; } // 记录加载文件时间 G('loadTime'); // 运行应用 App::run(); }
/** * 加载主模板并缓存 * @access public * @param string $tmplTemplateFile 模板文件 * @param string $prefix 模板标识前缀 * @return string * @throws ThinkExecption */ public function loadTemplate($tmplTemplateFile, $prefix = '') { if (is_file($tmplTemplateFile)) { $this->templateFile = $tmplTemplateFile; // 读取模板文件内容 $tmplContent = file_get_contents($tmplTemplateFile); } else { $tmplContent = $tmplTemplateFile; } // 根据模版文件名定位缓存文件 $tmplCacheFile = $this->config['cache_path'] . $prefix . md5($tmplTemplateFile) . $this->config['cache_suffix']; // 判断是否启用布局 if (C('LAYOUT_ON')) { if (false !== strpos($tmplContent, '{__NOLAYOUT__}')) { // 可以单独定义不使用布局 $tmplContent = str_replace('{__NOLAYOUT__}', '', $tmplContent); } else { // 替换布局的主体内容 $layoutFile = THEME_PATH . C('LAYOUT_NAME') . $this->config['template_suffix']; $tmplContent = str_replace($this->config['layout_item'], $tmplContent, file_get_contents($layoutFile)); } } // 编译模板内容 $tmplContent = $this->compiler($tmplContent); Storage::put($tmplCacheFile, trim($tmplContent), 'tpl'); return $tmplCacheFile; }
/** * * @param string $fileName * @param string $fileContent * * @return self */ public static function put($fileName, $fileContent = '') { $model = \Storage::put($fileName, $fileContent); return self::query()->find($model->id); }
/** * @param $transaction * @throws CheckoutException */ public static function remove($transaction) { if (config('checkout.use_database') === true) { /** * @todo Add database support */ throw new CheckoutException('Database is not supported yet.'); } else { $file = \Storage::get(config('checkout.table_prefix') . 'Transactions'); $update = false; foreach (explode(PHP_EOL, $file) as $line) { $data = explode('|.', $line); if ($data[0] === $transaction) { $file = str_replace($line . PHP_EOL, '', $file); $update = true; break; } } if ($update) { \Storage::put(config('checkout.table_prefix') . 'Transactions', $file); } } }
public function doLoad(Request $request) { $input = $request->all(); $rules = ['productList' => 'required']; $messages = ['productList.required' => 'Es necesario seleccionar un archivo']; $validator = Validator::make($input, $rules, $messages); if ($validator->passes()) { Excel::load($request->file('productList'), function ($reader) { $rows = $reader->get(); foreach ($rows as $row) { $product = new Product(); $product->nombre = !empty($row->nombre) ? $row->nombre : ""; $product->barcode = !empty($row->barcode) ? $row->barcode : ""; $product->marca = !empty($row->marca) ? $row->marca : ""; $product->fuente = !empty($row->fuente) ? $row->fuente : ""; $product->denominacion_legal = !empty($row->denominacion_legal) ? $row->denominacion_legal : ""; $product->alimento = !empty($row->alimento) ? $row->alimento : ""; $product->unidad = !empty($row->unidad) ? $row->unidad : ""; $product->cantidad = !empty($row->cantidad) ? $row->cantidad : ""; $product->calorias = !empty($row->calorias) ? $row->calorias : ""; $product->calorias_porcentaje = !empty($row->calorias_porcentaje) ? $row->calorias_porcentaje : ""; $product->hidratos = !empty($row->hidratos) ? $row->hidratos : ""; $product->azucares = !empty($row->azucares) ? $row->azucares : ""; $product->sacarosa = !empty($row->sacarosa) ? $row->sacarosa : ""; $product->polidextro = !empty($row->polidextro) ? $row->polidextro : ""; $product->almidon = !empty($row->almidon) ? $row->almidon : ""; $product->polialcoholes = !empty($row->polialcoholes) ? $row->polialcoholes : ""; $product->fibra = !empty($row->fibra) ? $row->fibra : ""; $product->proteinas = !empty($row->proteinas) ? $row->proteinas : ""; $product->grasas = !empty($row->grasas) ? $row->grasas : ""; $product->ags = !empty($row->ags) ? $row->ags : ""; $product->agmi = !empty($row->agmi) ? $row->agmi : ""; $product->agpi = !empty($row->agpi) ? $row->agpi : ""; $product->trans = !empty($row->trans) ? $row->trans : ""; $product->colesterol = !empty($row->colesterol) ? $row->colesterol : ""; $product->epa = !empty($row->epa) ? $row->epa : ""; $product->dha = !empty($row->dha) ? $row->dha : ""; $product->omega_3 = !empty($row->omega_3) ? $row->omega_3 : ""; $product->omega_6 = !empty($row->omega_6) ? $row->omega_6 : ""; $product->omega_9 = !empty($row->omega_9) ? $row->omega_9 : ""; $product->sodio = !empty($row->sodio) ? $row->sodio : ""; $product->calcio = !empty($row->calcio) ? $row->calcio : ""; $product->hierro = !empty($row->hierro) ? $row->hierro : ""; $product->fosforo = !empty($row->fosforo) ? $row->fosforo : ""; $product->potasio = !empty($row->potasio) ? $row->potasio : ""; $product->magnesio = !empty($row->magnesio) ? $row->magnesio : ""; $product->selenio = !empty($row->selenio) ? $row->selenio : ""; $product->zinc = !empty($row->zinc) ? $row->zinc : ""; $product->vit_a_mc = !empty($row->vit_a_mc) ? $row->vit_a_mc : ""; $product->vit_a_ui = !empty($row->vit_a_ui) ? $row->vit_a_ui : ""; $product->vit_e_mc = !empty($row->vit_e_mc) ? $row->vit_e_mc : ""; $product->vit_e_ui = !empty($row->vit_e_ui) ? $row->vit_e_ui : ""; $product->vit_d = !empty($row->vit_d) ? $row->vit_d : ""; $product->b1 = !empty($row->b1) ? $row->b1 : ""; $product->b2 = !empty($row->b2) ? $row->b2 : ""; $product->niacina = !empty($row->niacina) ? $row->niacina : ""; $product->b6 = !empty($row->b6) ? $row->b6 : ""; $product->b9 = !empty($row->b9) ? $row->b9 : ""; $product->b12 = !empty($row->b12) ? $row->b12 : ""; $product->vit_c = !empty($row->vit_c) ? $row->vit_c : ""; $product->indice_glucemico = !empty($row->indice_glucemico) ? $row->indice_glucemico : ""; $product->alcohol = !empty($row->alcohol) ? $row->alcohol : ""; $product->calorias_alcohol = !empty($row->calorias_alcohol) ? $row->calorias_alcohol : ""; $product->descripcion = !empty($row->descripcion) ? $row->descripcion : ""; $product->ingredientes = !empty($row->ingredientes) ? $row->ingredientes : ""; $product->nombre_cientifico = !empty($row->nombre_cientifico) ? $row->nombre_cientifico : ""; $product->tags = !empty($row->tags) ? $row->tags : ""; $product->otros_nombres = !empty($row->otros_nombres) ? $row->otros_nombres : ""; $product->rnpa = !empty($row->rnpa) ? $row->rnpa : ""; $product->rne = !empty($row->rne) ? $row->rne : ""; $product->user_id = session('user')->id; $product->save(); $equivalences = !empty($row->equivalencias) ? array_map('trim', explode(',', $row->equivalencias)) : []; foreach ($equivalences as $equivalence) { $equivalence = explode(':', $equivalence); Equivalence::create(['product_id' => $product->id, 'name' => $equivalence[0], 'amount' => $equivalence[1]]); } $categories = array_map('trim', explode(',', $row->categorias)); $product->categories()->attach($categories); if (!empty($row->foto)) { $foto = file_get_contents($row->foto); $filename = basename($row->foto); $ext = explode('.', $filename)[1]; $filename = $product->id . '.' . $ext; \Storage::put('products/' . $filename, $foto); $product->foto = $filename; $product->save(); } else { $product->foto = ""; } } }); return response()->json(['status' => 'ok', 'url' => url('product/index')]); } else { return response()->json(['status' => 'error', 'message' => $validator->messages()->all()]); } }