当前位置: 首页>>代码示例>>PHP>>正文


PHP File::find方法代码示例

本文整理汇总了PHP中File::find方法的典型用法代码示例。如果您正苦于以下问题:PHP File::find方法的具体用法?PHP File::find怎么用?PHP File::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File的用法示例。


在下文中一共展示了File::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleRequest

 /**
  * Process all incoming requests passed to this controller, checking
  * that the file exists and passing the file through if possible.
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     // Copied from Controller::handleRequest()
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $url = array_key_exists('url', $_GET) ? $_GET['url'] : $_SERVER['REQUEST_URI'];
     // remove any relative base URL and prefixed slash that get appended to the file path
     // e.g. /mysite/assets/test.txt should become assets/test.txt to match the Filename field on File record
     $url = Director::makeRelative(ltrim(str_replace(BASE_URL, '', $url), '/'));
     $file = File::find($url);
     if ($this->canDownloadFile($file)) {
         // If we're trying to access a resampled image.
         if (preg_match('/_resampled\\/[^-]+-/', $url)) {
             // File::find() will always return the original image, but we still want to serve the resampled version.
             $file = new Image();
             $file->Filename = $url;
         }
         $this->extend('onBeforeSendFile', $file);
         return $this->sendFile($file);
     } else {
         if ($file instanceof File) {
             // Permission failure
             Security::permissionFailure($this, 'You are not authorised to access this resource. Please log in.');
         } else {
             // File doesn't exist
             $this->response = new SS_HTTPResponse('File Not Found', 404);
         }
     }
     return $this->response;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce-downloadableproduct,代码行数:37,代码来源:DownloadableFileController.php

示例2: authenticateFile

 public function authenticateFile()
 {
     $file_alias = $this->getParam('alias');
     $file = File::find('alias', $file_alias);
     if ($file == NULL) {
         System::displayError(System::getLanguage()->_('ErrorFileNotFound'), '404 Not Found');
     }
     $password = Utils::getPOST('password', '');
     $errorMsg = '';
     if (Utils::getPOST('submit', false) != false) {
         if ($file->verifyPassword($password)) {
             System::getSession()->setData('authenticatedFiles', array_merge(array($file->alias), System::getSession()->getData('authenticatedFiles', array())));
             System::forwardToRoute(Router::getInstance()->build('DownloadController', 'show', $file));
             exit;
         } else {
             $errorMsg = System::getLanguage()->_('InvalidPassword');
         }
     }
     $smarty = new Template();
     $smarty->assign('title', System::getLanguage()->_('Authenticate'));
     $smarty->assign('infoMsg', System::getLanguage()->_('ProtectedAccessAuthMsg'));
     $smarty->assign('errorMsg', $errorMsg);
     $smarty->requireResource('auth');
     $smarty->display('auth/file.tpl');
 }
开发者ID:nicefirework,项目名称:sharecloud,代码行数:25,代码来源:AuthController.class.php

示例3: loadFile

 private function loadFile()
 {
     if ($this->file != NULL) {
         return;
     }
     $this->file = File::find('alias', $this->getParam('alias', ''));
     if ($this->file == NULL) {
         System::displayError(System::getLanguage()->_('ErrorFileNotFound'), '404 Not Found');
     }
     if (System::getUser() != NULL) {
         $user_id = System::getUser()->uid;
     } else {
         $user_id = -1;
     }
     if ($user_id != $this->file->uid) {
         if ($this->file->permission == FilePermissions::PRIVATE_ACCESS) {
             System::displayError(System::getLanguage()->_('PermissionDenied'), '403 Forbidden');
             exit;
         } elseif ($this->file->permission == FilePermissions::RESTRICTED_ACCESS) {
             if (is_array(System::getSession()->getData("authenticatedFiles"))) {
                 if (!in_array($this->file->alias, System::getSession()->getData("authenticatedFiles"))) {
                     System::forwardToRoute(Router::getInstance()->build('AuthController', 'authenticateFile', $this->file));
                     exit;
                 }
             } else {
                 System::forwardToRoute(Router::getInstance()->build('AuthController', 'authenticateFile', $this->file));
                 exit;
             }
         }
     }
 }
开发者ID:nicefirework,项目名称:sharecloud,代码行数:31,代码来源:DownloadController.class.php

示例4: get_dl

 function get_dl($id = null)
 {
     $digitless = ltrim($id, '0..9');
     // file link can be either
     if ($digitless === '' or $digitless[0] === '.') {
         $file = File::find(strtok($id, '.'));
     } else {
         $file = File::where('name', '=', $id)->get();
     }
     if (!$file) {
         return;
     } elseif ($this->can('file.dl.deny.' . $file->id)) {
         return false;
     } else {
         $path = $file->file();
         $override = Event::until('file.dl.before', array(&$path, &$file, $this));
         if ($override !== null) {
             return $override;
         } elseif (!$file instanceof File) {
             return E_SERVER;
         } else {
             // In case the model was changed during event firing.
             $file->save();
             return Event::until('file.dl.response', array(&$path, $file, $this));
         }
     }
 }
开发者ID:SerdarSanri,项目名称:VaneMart,代码行数:27,代码来源:File.php

示例5: autoloader

 public static function autoloader($class)
 {
     // return if class already exists
     if (class_exists($class, FALSE)) {
         return TRUE;
     }
     // first check for a controller
     if (strstr($class, 'controller')) {
         // format to controller filename convention "c_<controller>.php"
         $file = 'c_' . str_replace('_controller', '', $class);
         if ($path = File::find('controllers/' . $file)) {
             require $path;
             return TRUE;
         } else {
             return FALSE;
         }
         // try the libraries folders
     } elseif ($path = File::find('libraries/' . $class)) {
         require $path;
         return TRUE;
         // try the vendors folders
     } elseif ($path = File::find('vendors/' . $class . '/' . $class)) {
         require $path;
         return TRUE;
     }
     // couldn't find the file
     return FALSE;
 }
开发者ID:rebekahheacock,项目名称:dwa15-archive,代码行数:28,代码来源:File.php

示例6: edit

 /**
  * Show the form for editing the specified file meta.
  *
  * @param  int $id
  * @return \Response
  * @throws \Exception
  */
 public function edit($id)
 {
     $file = File::find($id);
     if ($file) {
         return $this->theme->ofWithLayout('partials.file_config_form', compact('file'));
     }
     throw new \Exception('Unable to find file, it may no longer exist');
 }
开发者ID:spetross,项目名称:ugvoice,代码行数:15,代码来源:AssetController.php

示例7: image

 function image($width = null)
 {
     if (!func_num_args()) {
         return $this->image ? File::find($this->image) : null;
     } elseif ($image = $this->image()) {
         $source = $image->file();
         return Block_Thumb::url(compact('width', 'source'));
     }
 }
开发者ID:SerdarSanri,项目名称:VaneMart,代码行数:9,代码来源:Product.php

示例8: search_files

 function search_files()
 {
     if (isset($_POST['search']) && $_POST['search'] != "") {
         $search = " name LIKE '%" . $_POST['search'] . "%' ";
     } else {
         $files = File::find('all');
     }
     echo FileWrapper::display($files);
     wp_die();
 }
开发者ID:mawilliamson,项目名称:version-control,代码行数:10,代码来源:VersionPostPage.php

示例9: run

 /**
  * @var bool $enabled If set to FALSE, keep it from showing in the list
  * and from being executable through URL or CLI.
  *
  * @access public
  * @param SS_Request
  */
 public function run($request)
 {
     $dbFilename = $request->getVar('db') ? $request->getVar('db') : 'database.sql.gz';
     $file = File::find($dbFilename);
     if (!$this->checkExtension($dbFilename) || !$file) {
         echo Debug::text("Sorry, either I could not find {$dbFilename} in assets or is not the right format");
         echo Debug::text("Only allowed file formats are .sql or .gz");
         exit;
     }
     // make sure existing DB tables are dropped
     if ($this->dropDBTables()) {
         $this->importSql($file);
     }
 }
开发者ID:shoaibali,项目名称:silverstripe-restoredb,代码行数:21,代码来源:RestoreDatabaseTask.php

示例10: find

 /**
  * Finds all CakeAdmin files in app/libs/admin
  *
  * @return array
  * @todo test me
  */
 function find()
 {
     $this->handler();
     $this->handler->cd(APPLIBS);
     $content = $this->handler->read();
     if (empty($content[0])) {
         return false;
     }
     if (!in_array('admin', $content[0])) {
         return false;
     }
     $this->handler->cd(APPLIBS . 'admin');
     $content = $this->handler->find('([a-z_]+)(.php)');
     return empty($content) ? false : $content;
 }
开发者ID:rchavik,项目名称:cake_admin,代码行数:21,代码来源:admin.php

示例11: routeRequest

/**
 * The request router looks at the URI path, tries to load it from /assets,
 * then tries to route the request through the Router if it's a model.
 * If it's not a model, the PageEngine tries to render the template file.
 */
function routeRequest()
{
    $path = getPath();
    if (!$path) {
        return PageEngine::renderPage('index');
    }
    if (File::find("assets/{$path}")) {
        File::render("assets/{$path}");
    }
    try {
        $router = new Router();
        return $router->route($path);
    } catch (ModelExistenceException $e) {
        return PageEngine::renderPage($path);
    }
}
开发者ID:asteig,项目名称:rabidcore,代码行数:21,代码来源:bootstrapper.php

示例12: saveInto

 public function saveInto(DataObjectInterface $record)
 {
     if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
         throw new Exception('HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.');
     }
     $htmlValue = Injector::inst()->create('HTMLValue', $this->value);
     // Sanitise if requested
     if ($this->config()->sanitise_server_side) {
         $santiser = Injector::inst()->create('HtmlEditorSanitiser', HtmlEditorConfig::get_active());
         $santiser->sanitise($htmlValue);
     }
     // Resample images and add default attributes
     if ($images = $htmlValue->getElementsByTagName('img')) {
         foreach ($images as $img) {
             // strip any ?r=n data from the src attribute
             $img->setAttribute('src', preg_replace('/([^\\?]*)\\?r=[0-9]+$/i', '$1', $img->getAttribute('src')));
             // Resample the images if the width & height have changed.
             if ($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))) {
                 $width = (int) $img->getAttribute('width');
                 $height = (int) $img->getAttribute('height');
                 if ($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) {
                     //Make sure that the resized image actually returns an image:
                     $resized = $image->ResizedImage($width, $height);
                     if ($resized) {
                         $img->setAttribute('src', $resized->getRelativePath());
                     }
                 }
             }
             // Add default empty title & alt attributes.
             if (!$img->getAttribute('alt')) {
                 $img->setAttribute('alt', '');
             }
             if (!$img->getAttribute('title')) {
                 $img->setAttribute('title', '');
             }
             // Use this extension point to manipulate images inserted using TinyMCE, e.g. add a CSS class, change default title
             // $image is the image, $img is the DOM model
             $this->extend('processImage', $image, $img);
         }
     }
     // optionally manipulate the HTML after a TinyMCE edit and prior to a save
     $this->extend('processHTML', $htmlValue);
     // Store into record
     $record->{$this->name} = $htmlValue->getContent();
 }
开发者ID:hpeide,项目名称:silverstripe-framework,代码行数:45,代码来源:HtmlEditorField.php

示例13: handleRequest

 /**
  * Handle the requests, checking the request file exists and is downloadable.
  * 
  * @param SS_HTTPRequest $request
  * @param DataModel $model
  * @return mixed null
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init()." . "Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     $address = $this->getRequest()->getVars();
     if (empty($address['url'])) {
         return;
     }
     // make the $url normalised as "assets/somefolder/somefile.ext, so we could find the file record if it has.
     $url = Director::makeRelative(ltrim(str_replace(BASE_URL, '', $address['url']), '/'));
     $file = File::find($url);
     $exists = $file && file_exists($file->getFullPath());
     // F/S check added to File::exists() in SS v3.2.0
     if ($exists) {
         if ($this->canSendToBrowser($file)) {
             //when requesting a re-sampled image, $file is the original image, hence we need to reset the file path
             if (preg_match('/_resampled\\/[^-]+-/', $url)) {
                 $file = new Image();
                 $file->Filename = $url;
             }
             $this->sendFileToBrowser($file);
         } else {
             if ($file instanceof Image) {
                 $this->sendLockpadSamepleImageToBrowser($file);
             } else {
                 $this->treatFileAccordingToStatus($file);
             }
         }
     }
 }
开发者ID:deviateltd,项目名称:silverstripe-advancedassets,代码行数:51,代码来源:SecuredFileController.php

示例14: find

 /**
  * Descends depth-first into directories, calling $closure
  * for each file or directory, depending on $excludeDirs
  *
  * @param mixed $closure a user function, as defined by call_user_func
  * @param string $path the starting directory
  * @param bool $excludeDirs set to true to exclude directories (the default)
  * @return void
  */
 public static function find($closure, $path, $excludeDirs = true)
 {
     if (is_dir($path)) {
         if (!$excludeDirs) {
             call_user_func($closure, $path);
         }
     } else {
         call_user_func($closure, $path);
         return;
     }
     $fh = opendir($path);
     if (!$fh) {
         throw new Exception("{$path} does not exist or is inaccessible");
     }
     while (false !== ($file = readdir($fh))) {
         if ($file[0] == '.') {
             continue;
         }
         File::find($closure, "{$path}/{$file}", $excludeDirs);
     }
     closedir($fh);
 }
开发者ID:jcorbinredtree,项目名称:framework,代码行数:31,代码来源:File.php

示例15: updateOEmbedThumbnail

 /**
  * Fetch and update the media thumbnail
  */
 public function updateOEmbedThumbnail()
 {
     $oembed = $this->Media();
     if ($oembed && $oembed->thumbnail_url) {
         $fileName = preg_replace('/[^A-z0-9\\._-]/', '', $oembed->thumbnail_url);
         if ($existing = File::find($fileName)) {
             $this->MediaThumbID = $existing->ID;
         } else {
             $contents = @file_get_contents($oembed->thumbnail_url);
             if ($contents) {
                 $folder = Folder::find_or_make('downloaded');
                 file_put_contents($folder->getFullPath() . $fileName, $contents);
                 $file = Image::create();
                 $file->setFilename($folder->getFilename() . $fileName);
                 $file->ParentID = $folder->ID;
                 $this->MediaThumbID = $file->write();
             }
         }
     } else {
         $this->MediaThumbID = 0;
     }
 }
开发者ID:helpfulrobot,项目名称:bummzack-page-blocks,代码行数:25,代码来源:VideoBlock.php


注:本文中的File::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。