本文整理匯總了PHP中Illuminate\Support\Facades\File::exists方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::exists方法的具體用法?PHP File::exists怎麽用?PHP File::exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\File
的用法示例。
在下文中一共展示了File::exists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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';
}
示例2: getRename
/**
* @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';
}
示例3: checkSharedFolderExists
private function checkSharedFolderExists()
{
$path = $this->getPath('share');
if (!File::exists($path)) {
File::makeDirectory($path, $mode = 0777, true, true);
}
}
示例4: fire
/**
* Execute the console command.
*/
public function fire()
{
$this->line('');
$this->info('Routes file: app/routes.php');
$message = 'This will rebuild routes.php with all of the packages that' . ' subscribe to the `toolbox.routes` event.';
$this->comment($message);
$this->line('');
if ($this->confirm('Proceed with the rebuild? [Yes|no]')) {
$this->line('');
$this->info('Backing up routes.php ...');
// Remove the last backup if it exists
if (File::exists('app/routes.bak.php')) {
File::delete('app/routes.bak.php');
}
// Back up the existing file
if (File::exists('app/routes.php')) {
File::move('app/routes.php', 'app/routes.bak.php');
}
// Generate new routes
$this->info('Generating routes...');
$routes = Event::fire('toolbox.routes');
// Save new file
$this->info('Saving new routes.php...');
if ($routes && !empty($routes)) {
$routes = $this->getHeader() . implode("\n", $routes);
File::put('app/routes.php', $routes);
$this->info('Process completed!');
} else {
$this->error('Nothing to save!');
}
// Done!
$this->line('');
}
}
示例5: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// Check file exists
if (!File::exists($this->argument('file'))) {
$this->comment('No coverage file found, skipping.');
return 0;
}
// Open serialised file
$serialised = File::get($this->argument('file'));
if (!Str::startsWith($serialised, '<?php')) {
$coverage = unserialize($serialised);
// Require PHP object in file
} else {
$coverage = (require $this->argument('file'));
}
// Check coverage percentage
$total = $coverage->getReport()->getNumExecutableLines();
$executed = $coverage->getReport()->getNumExecutedLines();
$percentage = nf($executed / $total * 100, 2);
// Compare percentage to threshold
$threshold = $this->argument('threshold');
if ($percentage >= $threshold) {
$this->info("Code Coverage of {$percentage}% is higher than the minimum threshold required {$threshold}%!");
return;
}
// Throw error
$this->error("Code Coverage of {$percentage}% is below than the minimum threshold required {$threshold}%!");
return 1;
}
示例6: 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' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
}
}
}
示例7: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
if (Input::file()) {
$profile = $this->profile->find($this->user->profile->id);
$old = $profile->avatar;
$path = public_path() . '/images/profiles/' . $old;
if (File::exists($path)) {
File::delete($path);
}
}
$file = $request->file('file');
$filename = str_random(30) . time() . date('dmY') . '.' . $file->getClientOriginalExtension();
$file->move('images/profiles', $filename);
dd();
// save profile pic
if (Input::file()) {
$profile = $this->profile->find($this->user->profile->id);
$old = $profile->avatar;
$path = public_path() . '/images/profiles/' . $old;
if (File::exists($path)) {
File::delete($path);
}
$string = str_random(30);
$image = Input::file('image');
$filename = $string . time() . date('dmY') . '.' . $image->getClientOriginalExtension();
$path = public_path('/images/profiles/' . $filename);
Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
})->save($path, 60);
$profile->avatar = $filename;
$profile->save();
return redirect()->route('profiles.index');
}
}
示例8: upload
public function upload()
{
if (Session::get('isLogged') == true) {
return \Plupload::file('file', function ($file) {
// екстракт на наставката
$originName = $file->getClientOriginalName();
$array = explode('.', $originName);
$extension = end($array);
// името без наставка
$name = self::normalizeString(pathinfo($originName, PATHINFO_FILENAME));
// base64 од името на фајлот
$fileName = base64_encode($name) . '.' . $extension;
// пат до фајлот
$path = storage_path() . '\\upload\\' . Session::get('index') . '\\' . $fileName;
if (!File::exists($path)) {
// фајловите се чуваат во storage/upload/brIndeks/base64(filename).extension
$file->move(storage_path('upload/' . Session::get('index')), $fileName);
return ['success' => true, 'message' => 'Upload successful.', 'deleteUrl' => action('FileController@delete', [$file])];
} else {
return ['success' => false, 'message' => 'File with that name already exists!', 'deleteUrl' => action('FileController@delete', [$file])];
}
});
} else {
abort(404);
}
}
示例9: 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' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
}
}
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$rules = ['name' => ['required', 'unique:archive,name', 'regex:' . config('app.expressions.dir')]];
if ($this->systemAdmin) {
$rules['department_id'] = 'required';
}
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
DB::transaction(function () use($request) {
#add all papers from department to archive
$archive = Archive::create($request->all());
$department = Department::findOrFail($request->get('department_id'));
$paperObj = new PaperClass();
$archivePath = 'archive/';
if (!File::exists($archivePath . $archive->name)) {
File::makeDirectory($archivePath . $archive->name);
}
$newPath = $archivePath . $archive->name . '/';
$oldPath = $paperObj->prefix() . '/' . $department->keyword . '/';
foreach ($department->papers()->archived()->get() as $paper) {
$paper->archive()->associate($archive);
$paper->save();
File::move($oldPath . $paper->source, $newPath . $paper->source);
if ($paper->payment_source) {
File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source);
}
}
});
return redirect()->action('Admin\\ArchiveController@index')->with('success', 'updated');
}
示例11: putEdit
public function putEdit(Request $request)
{
if (!ACL::hasPermission('winners2014', 'edit')) {
return redirect(route('winners2014'))->withErrors(['Você não pode editar os ganhadores de 2014.']);
}
$this->validate($request, ['category' => 'required', 'position' => 'required', 'name' => 'required|max:50', 'city' => 'required|max:45', 'state' => 'required|max:2|min:2', 'quantityVotes' => 'required|numeric', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['category.required' => 'Escolha a categoria', 'position.required' => 'Escolha a posição', 'name.required' => 'Informe o nome do ganhador', 'name.max' => 'O nome do ganhador não pode passar de :max caracteres', 'city.required' => 'Informe o nome da cidade do ganhador', 'city.max' => 'O nome da cidade não pode passar de :max caracteres', 'state.required' => 'Informe o Estado do ganhador', 'state.max' => 'O UF do Estado deve ter apenas :max caracteres', 'state.min' => 'O UF do Estado deve ter apenas :min caracteres', 'quantityVotes.required' => 'Informe a quantidade de votos', 'quantityVotes.numeric' => 'Somente números são aceitos', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif, .bmp e .png']);
$winner = WinnersLastYear::find($request->winnersLastYearId);
$winner->category = $request->category;
$winner->position = $request->position;
$winner->name = $request->name;
$winner->city = $request->city;
$winner->state = $request->state;
$winner->quantityVotes = $request->quantityVotes;
if ($request->photo) {
//DELETE OLD PHOTO
if ($request->currentPhoto != "") {
if (File::exists($this->folder . $request->currentPhoto)) {
File::delete($this->folder . $request->currentPhoto);
}
}
$extension = $request->photo->getClientOriginalExtension();
$namePhoto = Carbon::now()->format('YmdHis') . "." . $extension;
$img = Image::make($request->file('photo'));
if ($request->photoCropAreaW > 0 or $request->photoCropAreaH > 0 or $request->photoPositionX or $request->photoPositionY) {
$img->crop($request->photoCropAreaW, $request->photoCropAreaH, $request->photoPositionX, $request->photoPositionY);
}
$img->resize($this->photoWidth, $this->photoHeight)->save($this->folder . $namePhoto);
$winner->photo = $namePhoto;
}
$winner->save();
$success = "Ganhador editado com sucesso";
return redirect(route('winners2014'))->with(compact('success'));
}
示例12: getImageUrl
public static function getImageUrl($filename, $size = '', $default = '')
{
if (filter_var($filename, FILTER_VALIDATE_URL)) {
return $filename;
}
$image = '';
if ($filename != '' && strlen($filename) !== 0) {
if ($size !== '') {
if (File::exists(public_path('images/uploads' . self::getImage($filename, $size)))) {
$image = asset('images/uploads' . self::getImage($filename, $size));
} else {
if (File::exists(public_path('images/uploads' . $filename))) {
$image = asset('images/uploads' . $filename);
} else {
$image = asset('images/uploads' . self::getImage($default, $size));
}
}
} else {
if (File::exists(public_path('/images/uploads' . $filename))) {
$image = asset('images/uploads' . $filename);
} else {
$image = asset('images/uploads' . self::getImage($default, $size));
}
}
} else {
$image = asset('images/uploads' . self::getImage($default, $size));
}
return $image;
}
示例13: imageAvatar
protected function imageAvatar()
{
$path = 'upload/' . date('Ym/d/');
$filename = KRandom::getRandStr() . '.jpg';
if (!File::exists(public_path($path))) {
File::makeDirectory(public_path($path), 493, true);
}
while (File::exists(public_path($path) . $filename)) {
$filename = KRandom::getRandStr() . '.jpg';
}
$this->image->resize(new \Imagine\Image\Box(300, 300))->save(public_path($path) . $filename);
ImageModel::createUploadedImage($path . $filename, URL::asset($path . $filename));
$user = AuthModel::user();
$url = URL::asset($path . $filename);
if ($user) {
if ($user->profile) {
$user->profile->avatar = $url;
$user->profile->save();
} else {
ProfileModel::create(array('user_id' => $user->id, 'avatar' => $url));
}
} else {
}
return $url;
}
示例14: save
public function save(Request $request)
{
$rules = array('colour_code' => 'required', 'w_texture' => 'required|notcontains0');
$messages = ['w_texture.required' => 'Je moet een texture image uploaden', 'colour_code.required' => 'Koppel een kleur aan deze texture', 'w_texture.notcontains0' => "Er was geen texture image crop selectie"];
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
return redirect('/cms/texture/create')->withErrors($validator)->withInput();
} else {
$file = $request->file('slider_img');
$fileUploadDir = 'files/uploads/';
$fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
if (File::exists($fileUploadDir . $fileName)) {
$fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
}
$this->dispatch(new ProcessTextures($fileName));
if ($fileName) {
$texture = new Texture();
$texture->title = $request->get("slider_title");
$texture->img = $fileName;
$texture->colour_id = $request->get("colour_code");
$texture->save();
}
return redirect('/cms/texture');
}
}
示例15: getAlbumsList
public function getAlbumsList()
{
$directoryPath = $this->getAlbumsFolderLocation();
$albums_list = array();
$list = null;
if (File::exists($directoryPath)) {
$list = File::directories($directoryPath);
}
if ($list != null) {
foreach ($list as $album) {
$locationExplode = explode("/", $album);
$folderName = end($locationExplode);
if (!StringUtils::getInstance()->startsWith($folderName, "hidden_")) {
if ($this->isAlbumList($album)) {
$titleFilePath = $album . DIRECTORY_SEPARATOR . "title.txt";
if (File::exists($titleFilePath)) {
array_push($albums_list, $album);
}
} else {
array_push($albums_list, $album);
}
}
}
}
return $albums_list;
}