isFile() public static method

Determine if the given path is a file.
public static isFile ( string $file ) : boolean
$file string
return boolean
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['opening' => 'required', 'dimensions' => 'required', 'address' => 'required', 'capacity' => 'required']);
     $santiago = Santiago::find($id);
     if ($request->file('edit-santiago-photo')) {
         $this->validate($request, ['edit-santiago-photo' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg']);
         $santiagoFile = $santiago->photo_path . $santiago->photo_name;
         if (\File::isFile($santiagoFile)) {
             \File::delete($santiagoFile);
         }
         $file = $request->file('edit-santiago-photo');
         $santiago_photo_path = $this->_santiago_photo_path;
         $santiago_photo_name = $file->getClientOriginalName();
         $file->move($santiago_photo_path, $santiago_photo_name);
         $santiago->photo_name = $santiago_photo_name;
         $santiago->photo_path = $santiago_photo_path;
     }
     $santiago->opening = $request->get('opening');
     $santiago->dimensions = $request->get('dimensions');
     $santiago->address = $request->get('address');
     $santiago->capacity = $request->get('capacity');
     $santiago->save();
     flash()->success('', 'Santiago redaguotas!');
     return Redirect::to('/dashboard/santiago/');
 }
Example #2
0
 public function update(Request $request, $id)
 {
     $this->validate($request, ['name' => 'required', 'lastname' => 'required', 'password' => 'required|min:6', 'email' => 'required|email']);
     $user = User::find($id)->first();
     if ($request->file('edit-user-photo')) {
         $this->validate($request, ['edit-user-photo' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg']);
         $userFile = $user->avatar_path . $user->avatar;
         if (\File::isFile($userFile)) {
             \File::delete($userFile);
         }
         $file = $request->file('edit-user-photo');
         $avatar_path = $this->_user_photo_path;
         $avatar = $file->getClientOriginalName();
         $file->move($avatar_path, $avatar);
         $user->avatar = $avatar;
         $user->avatar_path = $avatar_path;
     }
     $user->name = $request->get('name');
     $user->lastname = $request->get('lastname');
     $user->email = $request->get('email');
     $user->password = bcrypt($request->get('password'));
     $user->save();
     flash()->success('', 'Redaguotas!');
     return redirect()->back();
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     foreach ($this->helpers as $helper) {
         $helper_path = app_path() . '/Helpers/' . $helper . '.php';
         if (\File::isFile($helper_path)) {
             require_once $helper_path;
         }
     }
 }
Example #4
0
 public function __construct(File $file)
 {
     if (!$file->isFile()) {
         throw new CsvParseException("Could not open file");
     }
     $this->filepath = $file;
     $this->index = -1;
     $this->currentline = null;
     $this->file = null;
 }
Example #5
0
 public function getExtraSecondaryAttribute($value)
 {
     $live_path = 'uploads/thumbs/';
     $location = public_path($live_path);
     $filename = $this->hash . "_bg" . "." . pathinfo($value, PATHINFO_EXTENSION);
     if (\File::isFile($location . $filename)) {
         return asset($live_path . $filename);
     }
     return $value;
 }
Example #6
0
 public function uploadFile($file)
 {
     if (File::isFile($file)) {
         $path = Config::get('constant.path_annex');
         $name = $this->id . '.' . $file->getClientOriginalExtension();
         $url = $path . '/' . $name;
         $file->move($path, $name);
         $this->url = $url;
         $this->save();
     }
 }
Example #7
0
 private function __actionFile()
 {
     $FileManager =& $this->_Parent->ExtensionManager->create('filemanager');
     $context = $this->_context;
     array_shift($context);
     $path = DOCROOT . $FileManager->getStartLocation() . (is_array($context) && !empty($context) ? '/' . implode('/', $context) . '/' : NULL);
     $permission = $_POST['fields']['file']['permissions'];
     $content = $_POST['fields']['file']['contents'];
     $filename = $_POST['fields']['file']['name'];
     $file = new File($path . '/' . $filename);
     $file->setContents($content);
     $file->setPermissions($permission);
     return $file->isFile();
 }
Example #8
0
 /** 
  * Force a file download by setting headers.  
  * @param string path to file 
  * @param string extension 
  * @param string file name on client side  
  * @example download('folder/error_log.pdf') 
  * @example download('folder/error_log.pdf', 'pdf' ,'log.pdf')  
  * @return boolean
  */
 public static function download($path = false, $extension = false, $name = false)
 {
     if ($path && File::isFile($path)) {
         if (!$extension) {
             $extension = File::extension($path);
         }
         if (!$name) {
             $name = basename($path);
         }
         header('Content-Type: application/' . $extension);
         header("Content-Transfer-Encoding: Binary");
         header("Content-disposition: attachment; filename=" . $name);
         readfile($path);
         exit;
     }
     return false;
 }
 public function register()
 {
     // Add gallery css to backend forms
     Event::listen('backend.form.extendFields', function ($widget) {
         $pages = ['RainLab\\Blog\\Models\\Post'];
         if (in_array(get_class($widget->model), $pages)) {
             // Add our gallery styles
             $widget->getController()->addCss('/plugins/nsrosenqvist/baguettegallery/assets/css/gallery_layouts.css');
             $theme = Theme::getActiveTheme();
             // Check if the theme has a css file that needs to be included too
             if (Filesystem::isFile($theme->getPath() . '/partials/baguetteGallery/galleries.css')) {
                 $themeDir = '/' . ltrim(Config::get('cms.themesPath'), '/') . '/' . $theme->getDirName();
                 $widget->getController()->addCss($themeDir . '/partials/baguetteGallery/galleries.css');
             }
         }
     });
 }
 public function testWrite()
 {
     $file = new File('/tmp/test');
     $this->assertEquals(true, $file->append("test\n"));
     $this->assertEquals(true, $file->append("test\n"));
     $this->assertEquals(true, $file->copy('/tmp/test2'));
     $this->assertEquals(true, $file->delete());
     $file = new File('/tmp/test2');
     $linecount = 0;
     foreach ($file->lines() as $line) {
         $linecount = $linecount + 1;
     }
     $array = $file->toArray();
     $this->assertEquals(2, count($array));
     $this->assertEquals(2, $linecount);
     $this->assertEquals(true, $file->delete());
     $this->assertEquals(false, $file->isFile());
 }
Example #11
0
 public function __construct(File $file, CsvParser $settings)
 {
     if (!$file->isFile()) {
         throw new CsvParseException("Could not open file");
     }
     $this->index = 0;
     $this->currentline = null;
     $this->header = null;
     $this->columncount = null;
     $this->file = fopen($file, 'r');
     $this->settings = $settings;
     if ($this->settings->hasHeader()) {
         $temp = $this->parseLine();
         if (!is_array($temp)) {
             throw new CsvParseException("Could not parse header");
         }
         $this->header = $temp;
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $namespace = "Tablas";
     //borrramos generaciones previas
     File::deleteDirectory(app_path('contraladores_generados'));
     //creamos el directorio en app..
     File::makeDirectory(app_path('contraladores_generados'), 777);
     $this->info("Buscando modelos");
     $models = File::files(app_path('models'));
     foreach ($models as $model) {
         if (File::isFile($model)) {
             $baseText = File::get(app_path('controllers/templates/Template.txt'));
             $controllerName = str_plural_spanish(str_replace('.php', '', basename($model))) . 'Controller';
             $this->info("Generando controller: " . $controllerName);
             //replace class name..
             $baseText = str_replace('@class_name@', $controllerName, $baseText);
             //replace namespace..
             $baseText = str_replace('@namespace@', $namespace, $baseText);
             File::put(app_path('contraladores_generados/' . $controllerName . '.php'), $baseText);
         }
     }
 }
Example #13
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //borrramos generaciones previas
     File::deleteDirectory(app_path('vistas_generadas'));
     //creamos el directorio en app..
     File::makeDirectory(app_path('vistas_generadas'), 777);
     $this->info("Buscando modelos");
     $models = File::files(app_path('models'));
     foreach ($models as $model) {
         if (File::isFile($model)) {
             $modelName = str_replace('.php', '', basename($model));
             if ($modelName != 'BaseModel') {
                 $modelInstance = new $modelName();
                 $collectionName = lcfirst(str_plural_spanish($modelName));
                 $baseText = File::get(app_path('controllers/templates/View.txt'));
                 $baseText = str_replace('@model_name@', $modelName, $baseText);
                 $baseText = str_replace('@pretty_name@', $modelInstance->getPrettyName(), $baseText);
                 $baseText = str_replace('@collection_name@', $collectionName, $baseText);
                 $basePath = app_path('vistas_generadas');
                 $this->info("Generando vista: " . $collectionName);
                 File::put($basePath . '/' . $collectionName . '.blade.php', $baseText);
                 $baseText = File::get(app_path('controllers/templates/Form.txt'));
                 $baseText = str_replace('@var_name@', lcfirst($modelName), $baseText);
                 $baseText = str_replace('@pretty_name@', $modelInstance->getPrettyName(), $baseText);
                 $baseText = str_replace('@collection_name@', $collectionName, $baseText);
                 $fieldsStr = "";
                 $fields = $modelInstance->getFillable();
                 foreach ($fields as $key) {
                     $fieldsStr .= "{{Form::btInput(\$" . lcfirst($modelName) . ", '" . $key . "', 6)}}" . PHP_EOL;
                 }
                 $baseText = str_replace('@fields@', $fieldsStr, $baseText);
                 $basePath = app_path('vistas_generadas');
                 $this->info("Generando formulario: " . $collectionName);
                 File::put($basePath . '/' . $collectionName . 'form.blade.php', $baseText);
             }
         }
     }
 }
Example #14
0
 /**
  * Upload an image
  * Validates is an image
  * Saves image through intervention, optimizing and constraining to max size
  * Saves to public/uploads directory, with unique filename
  * @return string $image filename | throws Exception on error
  */
 public function process($file)
 {
     // Make sure upload directory exists
     static::directoryExists(public_path() . '/' . $this->uploadDirectory);
     // Validate file is image
     $validation = Validator::make(['file' => $file], ['file' => 'mimes:jpeg,png,gif']);
     if (!$validation->fails()) {
         $destination = public_path() . '/' . $this->uploadDirectory . '/' . $file->getClientOriginalName();
         if (File::isFile($destination)) {
             $basename = basename(isset($file->fileSystemName) ? $file->fileSystemName : $file->getClientOriginalName(), $file->getClientOriginalExtension());
             // Remove trailing period
             $basename = rtrim($basename, '.');
             // Append 1 and recheck
             $counter = 1;
             $destination = public_path() . '/' . $this->uploadDirectory . '/' . $basename . '_' . $counter . '.' . $file->getClientOriginalExtension();
             while (File::isFile($destination)) {
                 $counter++;
                 $destination = public_path() . '/' . $this->uploadDirectory . '/' . $basename . '_' . $counter . '.' . $file->getClientOriginalExtension();
             }
         }
         // Constrain image to maximum width if needed, respecting aspect ratio
         Image::make($file)->widen(1200, function ($constraint) {
             $constraint->upsize();
         })->save($destination);
         // Image has been saved to it's destination, set attributes
         if (empty($this->user_id)) {
             $user = Confide::user();
             $this->user_id = $user->id;
         }
         $this->path = $this->uploadDirectory;
         $this->filename = str_replace(public_path() . '/' . $this->uploadDirectory . '/', '', $destination);
         $this->save();
         return;
     }
     throw new Exception("There was an error uploading the image. Please upload an image with jpg, png or gif filetype");
 }
Example #15
0
out::prntln("Last index of 'o': " . ((!$hello->lastIndexOf("o")) ? 'false' :  $hello->lastIndexOf("o")));

// ----------------------------------------------------- //

// New Section
out::prntln();

// ----------------------------------------------------- //

// Initialize a File
$file = new File("index.php");

// Get the name
out::prntln("Filename? " . $file->getName());

// Is it a file?
out::prntln("File? " . (($file->isFile()) ? 'true' : 'false'));

// Check validation.
out::prntln("Does it exist? " . (($file->exists()) ? 'true' : 'false'));

// Attempt creation
out::prntln("Creation? " . (($file->createNewFile()) ? 'true' : 'false'));

// Size?
out::prntln("Size: " . $file->length());

// Last modified?
out::prntln("Last modified: " . $file->lastModified());

// ----------------------------------------------------- //
Example #16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $team = Team::find($id);
     $path = $team->logo_path;
     $name = $team->logo_name;
     $file = $path . $name;
     if (\File::isFile($file)) {
         \File::delete($file);
     }
     $team->delete();
     flash()->success('', 'Komanda ištrinta!');
     return Redirect::to('/dashboard/teams/');
 }
Example #17
0
<?php

apd_set_pprof_trace();
require_once '../../lib/base/boot.php';
$f = new File(__FILE__);
var_dump($f->isDir());
var_dump($f->isFile());
$f->copyTo('/tmp/test');
#$t = getrusage();
#$t = doubleval($t['ru_utime.tv_sec']*1000) + doubleval($t['ru_utime.tv_usec']/1000000);
#printf("User time: %f", $t);
 public static function makeBaguetteGallery($images, $layout = "", $class = "")
 {
     // Set component properties
     if (empty($class)) {
         $class = self::$defaultClass;
     }
     if (empty($layout)) {
         $layout = self::$defaultLayout;
     }
     $parameters = ['layout' => $layout, 'class' => $class, 'images' => []];
     foreach ($images as $key => $val) {
         $parameters['images'][$key] = new BaguetteImage($val, true);
     }
     // Get twig runtime
     $twig = App::make('twig.environment');
     $partial = null;
     $result = "";
     // Create an instance of the component
     $manager = ComponentManager::instance();
     $component = $manager->makeComponent(self::$componentName, null, $parameters);
     $component->init();
     $component->alias = self::$componentName;
     // Try first to find a partial from the theme
     $overrideName = $component->alias . '/' . $parameters['layout'];
     if (Filesystem::isFile(Theme::getActiveTheme()->getPath() . '/partials/' . $overrideName . '.htm')) {
         $partial = Partial::loadCached(Theme::getActiveTheme(), $overrideName);
     }
     // If not found we use one from the plugin
     if (is_null($partial)) {
         if (Filesystem::isFile(plugins_path() . '/nsrosenqvist/baguettegallery/components/baguettegallery/' . $parameters['layout'] . '.htm')) {
             $partial = ComponentPartial::loadCached($component, $parameters['layout']);
         } else {
             $partial = ComponentPartial::loadCached($component, self::$defaultLayout);
         }
     }
     // Render the component
     if (!is_null($partial) && !empty($images)) {
         $template = $twig->loadTemplate($partial->getFullPath());
         $result = $template->render($parameters);
     }
     return $result;
 }
Example #19
0
 /**
  * Sets up the environment for toExecute and then runs it.
  * @param Commandline $toExecute
  * @throws BuildException
  */
 protected function runCommand(Commandline $toExecute)
 {
     // We are putting variables into the script's environment
     // and not removing them (!)  This should be fine, but is
     // worth remembering and testing.
     if ($this->port > 0) {
         putenv("CVS_CLIENT_PORT=" . $this->port);
     }
     // Need a better cross platform integration with <cvspass>, so
     // use the same filename.
     if ($this->passFile === null) {
         $defaultPassFile = new PhingFile(Phing::getProperty("cygwin.user.home", Phing::getProperty("user.home")) . DIRECTORY_SEPARATOR . ".cvspass");
         if ($defaultPassFile->exists()) {
             $this->setPassfile($defaultPassFile);
         }
     }
     if ($this->passFile !== null) {
         if ($this->passFile->isFile() && $this->passFile->canRead()) {
             putenv("CVS_PASSFILE=" . $this->passFile->__toString());
             $this->log("Using cvs passfile: " . $this->passFile->__toString(), Project::MSG_INFO);
         } elseif (!$this->passFile->canRead()) {
             $this->log("cvs passfile: " . $this->passFile->__toString() . " ignored as it is not readable", Project::MSG_WARN);
         } else {
             $this->log("cvs passfile: " . $this->passFile->__toString() . " ignored as it is not a file", Project::MSG_WARN);
         }
     }
     if ($this->cvsRsh !== null) {
         putenv("CVS_RSH=" . $this->cvsRsh);
     }
     // Use the ExecTask to handle execution of the command
     $exe = new ExecTask($this->project);
     $exe->setProject($this->project);
     //exe.setAntRun(project);
     if ($this->dest === null) {
         $this->dest = $this->project->getBaseDir();
     }
     if (!$this->dest->exists()) {
         $this->dest->mkdirs();
     }
     if ($this->output !== null) {
         $exe->setOutput($this->output);
     }
     if ($this->error !== null) {
         $exe->setError($this->error);
     }
     $exe->setDir($this->dest);
     if (is_object($toExecute)) {
         $toExecuteStr = $toExecute->__toString();
         // unfortunately no more automagic for initial 5.0.0 release :(
     }
     $exe->setCommand($toExecuteStr);
     try {
         $actualCommandLine = $toExecuteStr;
         // we converted to string above
         $this->log($actualCommandLine, Project::MSG_INFO);
         $retCode = $exe->execute();
         $this->log("retCode=" . $retCode, Project::MSG_DEBUG);
         /*Throw an exception if cvs exited with error. (Iulian)*/
         if ($this->failOnError && $retCode !== 0) {
             throw new BuildException("cvs exited with error code " . $retCode . PHP_EOL . "Command line was [" . $toExecute->describeCommand() . "]", $this->getLocation());
         }
     } catch (IOException $e) {
         if ($this->failOnError) {
             throw new BuildException($e, $this->getLocation());
         } else {
             $this->log("Caught exception: " . $e, Project::MSG_WARN);
         }
     } catch (BuildException $e) {
         if ($this->failOnError) {
             throw $e;
         } else {
             $t = $e->getCause();
             if ($t === null) {
                 $t = $e;
             }
             $this->log("Caught exception: " . $t, Project::MSG_WARN);
         }
     } catch (Exception $e) {
         if ($this->failOnError) {
             throw new BuildException($e, $this->getLocation());
         } else {
             $this->log("Caught exception: " . $e, Project::MSG_WARN);
         }
     }
 }
Example #20
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::find($id);
     foreach ($post->photos as $photo) {
         $path = $photo->path;
         $name = $photo->name;
         $file = $path . $name;
         if (\File::isFile($file)) {
             \File::delete($file);
         }
     }
     $post->delete();
     flash()->success('Pavyko!', 'Naujiena ištrinta!');
     return redirect()->back();
 }
Example #21
0
 public function getDirectoryContents($filter = null, $directories_only = false, $files_only = false)
 {
     if (!$this->isDirectory()) {
         throw new Exception('Not a directory.');
     }
     $list = new ArrayList('File');
     foreach (scandir($this->path) as $file) {
         if ($file === '.' || $file === '..') {
             continue;
         }
         if ($filter !== null && !endsWith($file, $filter)) {
             continue;
         }
         $f = new File($file, $this);
         if ($directories_only && !$f->isDirectory()) {
             continue;
         }
         if ($files_only && !$f->isFile()) {
             continue;
         }
         $list->add($f);
     }
     return $list;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $player = Player::find($id);
     $file = $player->photo;
     if (\File::isFile($file)) {
         \File::delete($file);
     }
     $player->delete();
     flash()->success('', 'Žaidėjas panaikintas!');
     return redirect()->back();
 }
Example #23
0
 protected function fileExists($path)
 {
     return \File::isFile('../app/views/templates/' . $this->templateDirectory . '/' . $path . '.blade.php');
 }
//
//Route::get('admin/password_management', function()
//{
//    $active = "password_management";
//	return View::make('admin.password_management')->with('active', $active);
//});
//
//
//
//Route::get('admin/password_management', function()
//{
//    $active = "password_management";
//    return View::make('admin.password_management')->with('active', $active);
//});
//
//
//
Route::get('admission_form', function () {
    $file = public_path() . "/admission/admission_form.pdf";
    if (File::isFile($file)) {
        $file = File::get($file);
        $response = Response::make($file, 200);
        // using this will allow you to do some checks on it (if pdf/docx/doc/xls/xlsx)
        $response->header('Content-Type', 'application/pdf');
        return $response;
    }
    return Response::download($file);
});
Route::get('login', function () {
    return View::make('login');
});
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $league = League::find($id);
     $path = $league->logo_path;
     $name = $league->logo_name;
     $file = $path . $name;
     if (\File::isFile($file)) {
         \File::delete($file);
     }
     $league->delete();
     flash()->success('', 'Lyga ištrinta!');
     return redirect()->back();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['title' => 'required']);
     $country = Country::find($id);
     if ($request->file('edit-country-flag')) {
         $this->validate($request, ['edit-country-flag' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg']);
         $flagFile = $country->flag_path . $country->flag_name;
         if (\File::isFile($flagFile)) {
             \File::delete($flagFile);
         }
         $file = $request->file('edit-country-flag');
         $country_flag_path = $this->_country_flag_path;
         $country_flag_name = $file->getClientOriginalName();
         $file->move($country_flag_path, $country_flag_name);
         $country->flag_name = $country_flag_name;
         $country->flag_path = $country_flag_path;
     }
     $country->title = $request->get('title');
     $country->save();
     flash()->success('', 'Redaguota!');
     return Redirect::to('/dashboard/countries/');
 }
Example #27
0
File: File.php Project: rsms/phpab
 /** @ignore */
 public static function __test()
 {
     $file = new File(__FILE__);
     assert($file->exists());
     assert($file->isFile());
     assert(!$file->isDir());
     assert($file->isReadable());
 }