本文整理汇总了PHP中Illuminate\Support\Facades\File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$experiments = Experiment::active()->get();
$goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray());
$columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
$writer = new Writer(new SplTempFileObject());
$writer->insertOne($columns);
foreach ($experiments as $experiment) {
$engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
$row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
$results = $experiment->goals()->lists('count', 'name');
foreach ($goals as $column) {
$count = array_get($results, $column, 0);
$percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
$row[] = number_format($percentage, 2) . " % ({$count})";
}
$writer->insertOne($row);
}
$output = (string) $writer;
if ($file = $this->argument('file')) {
$this->info("Creating {$file}");
File::put($file, $output);
} else {
$this->line($output);
}
}
开发者ID:jamesblackwell,项目名称:laravel-experiments,代码行数:31,代码来源:ExportCommand.php
示例2: getRename
/**
* @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';
}
开发者ID:jayked,项目名称:laravel-filemanager,代码行数:28,代码来源:RenameController.php
示例3: saveCroppedImage
public function saveCroppedImage(Request $request, $slider_title = "")
{
$file = $request->file('slider_img');
if ($file && isset($_FILES["slider_img"]["tmp_name"])) {
try {
$slider_img_x = $_POST['x'];
$slider_img_y = $_POST['y'];
$slider_img_w = $_POST['w'];
$slider_img_h = $_POST['h'];
$display_w = $_POST['display_w'];
$file_path = $file->getPathname();
$orig_w = getimagesize($_FILES["slider_img"]["tmp_name"])[0];
$ratio = $orig_w / $display_w;
$fileUploadDir = 'files/uploads/';
$fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
if (File::exists($fileUploadDir . $fileName)) {
$fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
}
$img = \Img::make($file_path)->crop((int) ($slider_img_w * $ratio), (int) ($slider_img_h * $ratio), (int) ($slider_img_x * $ratio), (int) ($slider_img_y * $ratio));
$img = $img->resize(300, 300);
$tmpFile = $fileUploadDir . "tmp_slider_img" . time();
$img->save($tmpFile);
//merge two images to one
$this->merge('img/deze.png', $tmpFile, $fileUploadDir . $fileName, $slider_title, $request);
//delete tmp file
File::delete($tmpFile);
return $fileName;
} catch (Exception $e) {
return false;
}
}
return false;
}
开发者ID:leonstel,项目名称:czborduur,代码行数:33,代码来源:HomeSliderImageProcess.php
示例4: saveFileContents
protected function saveFileContents($fileName, $content)
{
$bytesWritten = File::put($fileName, $content);
if ($bytesWritten === false) {
dd('Error writing file: ' . $fileName);
}
}
开发者ID:rasmusebbesen,项目名称:barracuda,代码行数:7,代码来源:ContentController.php
示例5: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']);
if ($validator->fails()) {
return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput();
}
$riskManagements = RiskManagement::where('year', '=', $request->get('year'))->where('period', '=', $request->get('period'))->get();
if (sizeof($riskManagements) > 0) {
foreach ($riskManagements as $riskManagement) {
$filename = base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period') . '/' . $riskManagement->file_path;
if (File::exists($filename)) {
File::delete($filename);
}
RiskManagement::destroy($riskManagement->id);
}
}
if (Input::file('file')->isValid()) {
$filePath = date('Ymd_His') . '.pdf';
if (Input::file('file')->move(base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period'), $filePath)) {
//example of delete exist file
$riskManagement = new RiskManagement();
$riskManagement->file_path = $filePath;
$riskManagement->year = $request->get('year');
$riskManagement->period = $request->get('period');
$riskManagement->save();
return redirect('/admin/management');
} else {
return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
}
}
}
开发者ID:nettanawat,项目名称:Sfu-laravel,代码行数:37,代码来源:ManageriskController.php
示例6: down
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('pictures');
//delete everything inside the images directory
$path = public_path() . '/content/images/';
File::deleteDirectory($path, true);
}
开发者ID:elvinmakhmudov,项目名称:shopping.app,代码行数:12,代码来源:2015_09_13_162125_create_pictures_table.php
示例7: fire
/**
* @return void
*/
public function fire()
{
$database = $this->getDatabase($this->input->getOption('database'));
$this->checkDumpFolder();
//----------------
$dbfile = new BackupFile($this->argument('filename'), $database, $this->getDumpsPath());
$this->filePath = $dbfile->path();
$this->fileName = $dbfile->name();
$status = $database->dump($this->filePath);
$handler = new BackupHandler($this->colors);
// Error
//----------------
if ($status !== true) {
return $this->line($handler->errorResponse($status));
}
// Compression
//----------------
if ($this->isCompressionEnabled()) {
$this->compress();
$this->fileName .= ".gz";
$this->filePath .= ".gz";
}
$this->line($handler->dumpResponse($this->argument('filename'), $this->filePath, $this->fileName));
// S3 Upload
//----------------
if ($this->option('upload-s3')) {
$this->uploadS3();
$this->line($handler->s3DumpResponse());
if ($this->option('keep-only-s3')) {
File::delete($this->filePath);
$this->line($handler->localDumpRemovedResponse());
}
}
}
开发者ID:IuriiP,项目名称:db-backup,代码行数:37,代码来源:BackupCommand.php
示例8: saveImageLocally
/**
* @param \Onyx\Destiny\Objects\Hash $hash
* @param string $index
* @return bool
*/
public static function saveImageLocally($hash, $index = 'extra')
{
// BUG: Can't use variable object indexes implicitly
// $hash->{$index} should work but doesn't
// map the index explicitly with the attributes dumped into $bug
$bug = $hash->getAttributes();
$url = "https://bungie.net" . $bug[$index];
$name = $index != 'extra' ? '_bg' : null;
$name = $hash->hash . $name;
// Make sure we aren't trying to save something that isn't an image
// We only need this check because we cheat and store all hash related objects
// in one table. This means we have crazy cheats to get things done.
if (strlen($bug[$index]) < 5) {
return false;
}
$location = public_path('uploads/thumbs/');
$filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION);
if (File::isFile($location . $filename)) {
return true;
}
if ($hash instanceof Hash) {
$manager = new ImageManager();
try {
$img = $manager->make($url);
$img->save($location . $filename);
} catch (NotReadableException $e) {
Log::error('Could not download: ' . $url);
}
return true;
}
}
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:36,代码来源:Images.php
示例9: savePost
public function savePost()
{
$post = ['title' => Input::get('title'), 'content' => Input::get('content'), 'picture' => Input::get('picture')];
$rules = ['title' => 'required', 'content' => 'required'];
$valid = Validator::make($post, $rules);
if ($valid->passes()) {
$post = new Post($post);
$post->comment_count = 0;
$post->read_more = strlen($post->content) > 120 ? substr($post->content, 0, 120) : $post->content;
/*
$destinationPath = 'uploads'; // upload path
//$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
$fileName = time(); // renameing image
Input::file('images')->make($destinationPath, $fileName); // uploading file to given path
$post->images = Input::get($fileName);
$pic = Input::file('picture');
$pic_name = time();
Image::make($pic)->save(public_path().'/images/300x'.$pic_name);
$post->images = '/images/'.'300x'.$pic_name;
$post->images = Input::get($pic_name);
*/
$file = Request::file('picture');
$extension = $file;
Images::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
$post->images = $file->time();
$post->save();
return Redirect::to('admin/dash-board')->with('success', 'Post is saved!');
} else {
return Redirect::back()->withErrors($valid)->withInput();
}
}
开发者ID:singh7889,项目名称:Laravel-blog-post,代码行数:34,代码来源:PostController.php
示例10: run
public function run()
{
// get files in database/seeds folder
$path = base_path('database/seeds');
$files = array_map(function ($filename) {
return str_replace(".php", "", $filename);
}, array_map('basename', File::files($path)));
// get entries in database
$seeded = DB::table('seeded')->lists('seeder');
// find seeds that need to be done
foreach ($files as $file) {
if ($file == 'DatabaseSeeder') {
continue;
}
if (in_array($file, $seeded)) {
continue;
}
// call the seeder
Model::unguard();
$this->command->info("Calling {$file}");
try {
$this->call($file);
DB::table('seeded')->insert(['seeder' => $file]);
} catch (Exception $e) {
$this->command->error("Error in {$file}");
}
Model::reguard();
}
}
开发者ID:bespired,项目名称:tools,代码行数:29,代码来源:ToolsSeedSeeder.php
示例11: fire
public function fire()
{
$stubs = __DIR__ . '/stubs/lang.stub';
$name = strtolower($this->argument('name'));
$path = base_path('resources/lang/tr/admin/' . $name . '.php');
File::copy($stubs, $path);
}
开发者ID:vmajans,项目名称:create-app,代码行数:7,代码来源:ViewCommand.php
示例12: createTempDirectory
/**
* Create a directory to store some working files.
*
* @return string
*/
public function createTempDirectory()
{
$tempDirectory = storage_path('medialibrary/temp/' . str_random(16));
File::makeDirectory($tempDirectory, 493, true);
Gitignore::createIn(storage_path('medialibrary'));
return $tempDirectory;
}
开发者ID:RetinaInc,项目名称:laravel-medialibrary,代码行数:12,代码来源:FileManipulator.php
示例13: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (File::exists(Config::publishedSeederRealpath())) {
if (!$this->confirm('The seeder file already exists, overwrite it? [Yes|no]')) {
$this->line('');
return $this->info('Okay, no changes made to the file.');
}
}
// Laravel 5.0 does not have make:seed command
// in that case ignore the command and copy the contents
// of the file directly.
try {
$this->callSilent('make:seed', ['name' => Config::seederNameKey()]);
} catch (\Exception $ex) {
}
$inputFile = file_get_contents(Config::localSeederPath());
$outputFile = fopen(Config::publishedSeederRealpath(), 'w');
if ($inputFile && $outputFile) {
fwrite($outputFile, $inputFile);
fclose($outputFile);
} else {
File::delete(Config::publishedSeederRealpath());
$this->line('');
return $this->error('There was an error creating the seeder file, ' . 'check write permissions for database/seeds directory' . PHP_EOL . PHP_EOL . 'If you think this is a bug, please submit a bug report ' . 'at https://github.com/moharrum/laravel-geoip-world-cities/issues');
}
$this->line('');
$this->info('Okay, seeder file created successfully.');
}
开发者ID:moharrum,项目名称:laravel-geoip-world-cities,代码行数:33,代码来源:CreateCitiesSeederCommand.php
示例14: uploadW9
public function uploadW9(Request $request, $link, $app_name, $aff_code)
{
$affiliate_row = Affiliate::where('external_link', '=', $link)->first();
if ($affiliate_row == null) {
return redirect('error');
}
//$user_infusionsoft = UserInfusionsoft::where('app_name','=', $app_name)->first();
$user_infusionsoft = $affiliate_row->infusionsoft_user;
$app_infusionsoft = new iSDK();
if (!$app_infusionsoft->cfgCon($user_infusionsoft->app_name, $user_infusionsoft->app_apikey)) {
return redirect('error');
}
$file = $request->file('w9file');
if ($file) {
$extension = $file->getClientOriginalExtension();
$mimeType = $file->getMimeType();
if (strtolower($extension) != 'pdf' || $mimeType != 'application/pdf') {
return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'You can upload pdf files only.');
}
Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
$affiliate_row->w9_file_original_name = $file->getClientOriginalName();
$affiliate_row->w9_file = $file->getFilename() . '.' . $extension;
$affiliate_row->save();
return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('success', 'Congratulations! Your W9 is uploaded.');
}
return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'No file is selected.');
}
开发者ID:ruben-verhagen,项目名称:easy-affiliates,代码行数:27,代码来源:PublicAffiliateController.php
示例15: add
public function add()
{
$file = Request::file('file');
if (Request::hasFile('file')) {
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
$entry = new \App\File();
$entry->mime = $file->getClientMimeType();
$entry->original_filename = $file->getClientOriginalName();
$entry->filename = $file->getFilename() . '.' . $extension;
$entry->save();
$part = new Part();
$part->file_id = $entry->id;
$part->name = Request::input('name');
$part->sku = Request::input('sku');
$part->make = Request::input('make');
$part->year = Request::input('year');
$part->condition = Request::input('condition');
$part->description = Request::input('description');
$part->price = Request::input('price');
$part->imageurl = Request::input('imageurl');
if (Request::has('price')) {
$part->save();
}
}
return redirect('/admin/part');
}
开发者ID:kilis,项目名称:carshop,代码行数:27,代码来源:PartController.php
示例16: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store($image, $type, $primary_id, $current_link)
{
$image_link = array_key_exists($type, Input::all()) ? Input::file($type) != '' ? '/allgifted-images/' . $type . '/' . $primary_id . '.' . $image->getClientOriginalExtension() : $current_link : $current_link;
array_key_exists($type, Input::all()) ? File::exists(public_path($image_link)) ? File::delete(public_path($image_link)) : null : null;
$image ? Image::make($image)->fit(500, 300)->save(public_path($image_link)) : null;
return $image_link;
}
开发者ID:2ppaamm,项目名称:mathImageall,代码行数:13,代码来源:ImageController.php
示例17: boot
public static function boot()
{
parent::boot();
CourseGalleryItem::deleting(function ($courseGalleryItem) {
File::delete($courseGalleryItem->image);
});
}
开发者ID:TemRhythm,项目名称:priola-website,代码行数:7,代码来源:CourseGalleryItem.php
示例18: createFile
protected function createFile($fileName, $routeFile, $stubFile)
{
$stubFile = str_replace('{$NAME$}', $fileName, $stubFile);
if (File::put($routeFile, $stubFile)) {
$this->info('Route generated!');
}
}
开发者ID:draperstudio,项目名称:laravel-routie,代码行数:7,代码来源:GenerateRouTie.php
示例19: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'year' => 'required']);
if ($validator->fails()) {
return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput();
}
//example of delete exist file
$existMeetingReport = MeetingReport::where('year', '=', $request->get('year'))->where('no', '=', $request->get('no'))->first();
if ($existMeetingReport != null) {
$filename = base_path() . '/public/uploads/Meeting-reports/' . $request->get('year') . '/' . $existMeetingReport->file_path;
if (File::exists($filename)) {
File::delete($filename);
}
MeetingReport::destroy($existMeetingReport->id);
}
if (Input::file('file')->isValid()) {
$filePath = $request->get('no') . '.pdf';
if (Input::file('file')->move(base_path() . '/public/uploads/Meeting-reports/' . $request->get('year'), $filePath)) {
$meetingReport = new MeetingReport();
$meetingReport->file_path = $filePath;
$meetingReport->year = $request->get('year');
$meetingReport->no = $request->get('no');
$meetingReport->save();
return redirect('/admin/management');
} else {
return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
}
}
}
开发者ID:nettanawat,项目名称:Sfu-laravel,代码行数:35,代码来源:MeetingreportController.php
示例20: rmFile
public function rmFile($filename)
{
$fileUploadDir = 'files/uploads/';
if (File::exists($fileUploadDir . $filename)) {
File::delete($fileUploadDir . $filename);
}
}
开发者ID:leonstel,项目名称:czborduur,代码行数:7,代码来源:SliderController.php
注:本文中的Illuminate\Support\Facades\File类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论