本文整理匯總了PHP中File::path方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::path方法的具體用法?PHP File::path怎麽用?PHP File::path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類File
的用法示例。
在下文中一共展示了File::path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: send
/**
* @see parent::send()
*/
public function send()
{
$Resume = $this->getObject();
if ($Resume->IsFile) {
$this->attach(File::path($Resume), $Resume->Filename);
}
return parent::send();
}
示例2: path
/**
* ==========================================================
* GET SHIELD PATH BY ITS NAME
* ==========================================================
*
* -- CODE: -------------------------------------------------
*
* echo Shield::path('article');
*
* ----------------------------------------------------------
*
*/
public static function path($name)
{
$name = File::path($name) . '.' . File::E($name, 'php');
if ($path = File::exist(SHIELD . DS . Config::get('shield') . DS . ltrim($name, DS))) {
return $path;
} else {
if ($path = File::exist(ROOT . DS . ltrim($name, DS))) {
return $path;
}
}
return $name;
}
示例3: onCreateFileImageThumbnailSource
public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media = null)
{
// If we are on a private node, we won't do any remote calls (just as a precaution until
// we can configure this from config.php for the private nodes)
if (common_config('site', 'private')) {
return true;
}
if ($media !== 'image') {
return true;
}
// If there is a local filename, it is either a local file already or has already been downloaded.
if (!empty($file->filename)) {
return true;
}
$this->checkWhitelist($file->getUrl());
// First we download the file to memory and test whether it's actually an image file
$imgData = HTTPClient::quickGet($file->getUrl());
common_debug(sprintf('Downloading remote file id==%u with URL: %s', $file->id, $file->getUrl()));
$info = @getimagesizefromstring($imgData);
if ($info === false) {
throw new UnsupportedMediaException(_('Remote file format was not identified as an image.'), $file->getUrl());
} elseif (!$info[0] || !$info[1]) {
throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)'));
}
$filehash = hash(File::FILEHASH_ALG, $imgData);
try {
// Exception will be thrown before $file is set to anything, so old $file value will be kept
$file = File::getByHash($filehash);
//FIXME: Add some code so we don't have to store duplicate File rows for same hash files.
} catch (NoResultException $e) {
$filename = $filehash . '.' . common_supported_mime_to_ext($info['mime']);
$fullpath = File::path($filename);
// Write the file to disk if it doesn't exist yet. Throw Exception on failure.
if (!file_exists($fullpath) && file_put_contents($fullpath, $imgData) === false) {
throw new ServerException(_('Could not write downloaded file to disk.'));
}
// Updated our database for the file record
$orig = clone $file;
$file->filehash = $filehash;
$file->filename = $filename;
$file->width = $info[0];
// array indexes documented on php.net:
$file->height = $info[1];
// https://php.net/manual/en/function.getimagesize.php
// Throws exception on failure.
$file->updateWithKeys($orig, 'id');
}
// Get rid of the file from memory
unset($imgData);
$imgPath = $file->getPath();
return false;
}
示例4: create
/**
* Create a ZIP archive encoded in CP850 so that Windows will understand
* foreign characters
*
* @param File $archiveFile
* @param Folder $workingFolder
* @param Base[] $sources
* @param boolean $utf8 Set to true to use UTF8 encoding. This is not supported by Windows explorer.
* @throws Exception
*/
public static function create(File $archiveFile, Folder $workingFolder, $sources, $utf8 = false)
{
if (class_exists("\\ZipArchive") && !$utf8) {
\GO::debug("Using PHP ZipArchive");
$zip = new \ZipArchive();
$zip->open($archiveFile->path(), \ZipArchive::CREATE);
for ($i = 0; $i < count($sources); $i++) {
if ($sources[$i]->isFolder()) {
self::_zipDir($sources[$i], $zip, str_replace($workingFolder->path() . '/', '', $sources[$i]->path()) . '/');
} else {
$name = str_replace($workingFolder->path() . '/', '', $sources[$i]->path());
$name = @iconv('UTF-8', 'CP850//TRANSLIT', $name);
\GO::debug("Add file: " . $sources[$i]->path());
$zip->addFile($sources[$i]->path(), $name);
}
}
if (!$zip->close() || !$archiveFile->exists()) {
throw new \Exception($zip->getStatusString());
} else {
return true;
}
} else {
\GO::debug("Using zip exec");
if (!\GO\Base\Util\Common::isWindows()) {
putenv('LANG=en_US.UTF-8');
}
chdir($workingFolder->path());
$cmdSources = array();
for ($i = 0; $i < count($sources); $i++) {
$cmdSources[$i] = escapeshellarg(str_replace($workingFolder->path() . '/', '', $sources[$i]->path()));
}
$cmd = \GO::config()->cmd_zip . ' -r ' . escapeshellarg($archiveFile->path()) . ' ' . implode(' ', $cmdSources);
exec($cmd, $output, $ret);
if ($ret != 0 || !$archiveFile->exists()) {
throw new \Exception('Command failed: ' . $cmd . "<br /><br />" . implode("<br />", $output));
}
return true;
}
}
示例5: makeBackupFile
function makeBackupFile($user)
{
// XXX: this is pretty lose-y; try another way
$tmpdir = sys_get_temp_dir() . '/offline-backup/' . $user->nickname . '/' . common_date_iso8601(common_sql_now());
common_log(LOG_INFO, 'Writing backup data to ' . $tmpdir . ' for ' . $user->nickname);
mkdir($tmpdir, 0700, true);
$this->dumpNotices($user, $tmpdir);
$this->dumpFaves($user, $tmpdir);
$this->dumpSubscriptions($user, $tmpdir);
$this->dumpSubscribers($user, $tmpdir);
$this->dumpGroups($user, $tmpdir);
$fileName = File::filename($user->getProfile(), "backup", "application/atom+xml");
$fullPath = File::path($fileName);
$this->makeActivityFeed($user, $tmpdir, $fullPath);
$this->delTree($tmpdir);
return $fileName;
}
示例6: prepare
/**
* Get file name
*
* @param array $args $_REQUEST array
*
* @return success flag
*/
function prepare($args)
{
parent::prepare($args);
$filename = $this->trimmed('filename');
$path = null;
if ($filename && File::validFilename($filename)) {
$path = File::path($filename);
}
if (empty($path) or !file_exists($path)) {
$this->clientError(_('No such file.'), 404);
return false;
}
if (!is_readable($path)) {
$this->clientError(_('Cannot read file.'), 403);
return false;
}
$this->path = $path;
return true;
}
示例7: prepare
/**
* Get file name
*
* @param array $args $_REQUEST array
*
* @return success flag
*/
protected function prepare(array $args = array())
{
parent::prepare($args);
$filename = $this->trimmed('filename');
$path = null;
if ($filename && File::validFilename($filename)) {
$path = File::path($filename);
}
if (empty($path) or !file_exists($path)) {
// TRANS: Client error displayed when requesting a non-existent file.
$this->clientError(_('No such file.'), 404);
}
if (!is_readable($path)) {
// TRANS: Client error displayed when requesting a file without having read access to it.
$this->clientError(_('Cannot read file.'), 403);
}
$this->path = $path;
return true;
}
示例8: __new__
protected final function __new__($level, $value, $file = null, $line = null, $time = null)
{
if ($file === null) {
$debugs = debug_backtrace(false);
if (sizeof($debugs) > 4) {
list($dumy, $dumy, $dumy, $debug, $op) = $debugs;
} else {
list($dumy, $debug) = $debugs;
}
$file = File::path(isset($debug['file']) ? $debug['file'] : $dumy['file']);
$line = isset($debug['line']) ? $debug['line'] : $dumy['line'];
$class = isset($op['class']) ? $op['class'] : $dumy['class'];
}
$this->level = $level;
$this->file = $file;
$this->line = intval($line);
$this->time = $time === null ? time() : $time;
$this->class = $class;
$this->value = is_object($value) ? $value instanceof Exception ? array_merge(array($value->getMessage()), self::$exception_trace ? $value->getTrace() : array($value->getTraceAsString())) : clone $value : $value;
}
示例9: __setup_generate_model__
/**
* 既存のDBからモデルファイルを自動生成する
**/
public static function __setup_generate_model__(Request $request, $value)
{
if (!$request->is_vars('tables')) {
throw new RuntimeException('tables required');
}
$model_path = $request->is_vars('model_path') ? $request->in_vars('model_path') : path('libs/model');
$tables = $request->in_vars('tables');
$tables = strpos(',', $tables) === false ? array($tables) : explode(',', $tables);
foreach ($tables as $table) {
$dao = Dao::instant($table, $value);
$props = $dao->get_columns();
$properties = array();
foreach ($props as $prop_name) {
$property = new ModelProperty();
$property->name($prop_name);
foreach (self::$anons as $a) {
$anon = $dao->a($prop_name, $a);
if (isset(self::$defaults[$prop_name]) && self::$defaults[$prop_name] == $anon) {
continue;
}
if (!is_null($anon)) {
$property->annotation($a, $anon);
}
}
$properties[] = $property;
}
$class_name = preg_replace('/_(.)/e', 'ucfirst("\\1")', ucfirst(strtolower($table)));
$template = new Template();
$template->vars('properties', $properties);
$template->vars('class_name', $class_name);
$filename = File::path($model_path, $class_name . '.php');
$src = "<?php\n" . $template->read(module_templates('model.php'));
File::write($filename, $src);
// unset
$dao = $template = $properties = $property = null;
unset($dao);
unset($template);
unset($properties);
unset($property);
}
}
示例10: foreach
function copy_files()
{
$files = $this->get_files();
$paths = $this->project->file_paths();
foreach ($files as $file_parameters) {
$file_to_copy = new File($file_parameters);
$file_to_copy_url = $file_to_copy->path();
//create the file record
$file = new File();
$file->import_parameters_exactly($file_parameters);
//we want to create a new file so we need to reset the id. If we don't the app will just save our changes on
//the old file (bad idea)
$file->set('id', null);
$file->set('created_date', time());
$file->set('project_id', $this->project->id);
$file->save();
//copy the actual file
if (file_exists($file_to_copy_url)) {
copy($file_to_copy_url, $paths['upload_path'] . $file->name);
}
}
}
示例11: action
function action()
{
$FileManager =& $this->_Parent->ExtensionManager->create('filemanager');
$file = new File(DOCROOT . $FileManager->getStartLocation() . $_GET['file']);
if (isset($_POST['action']['save'])) {
$fields = $_POST['fields'];
$file->setName($fields['name']);
if (isset($fields['contents'])) {
$file->setContents($fields['contents']);
}
$file->setPermissions($fields['permissions']);
$relpath = str_replace(DOCROOT . $FileManager->getStartLocation(), NULL, dirname($_GET['file']));
if ($file->isWritable()) {
redirect($FileManager->baseURL() . 'properties/?file=' . rtrim(dirname($_GET['file']), '/') . '/' . $file->name() . '&result=saved');
} else {
redirect($FileManager->baseURL() . 'browse/' . $relpath);
}
} elseif (isset($_POST['action']['delete'])) {
General::deleteFile($file->path() . '/' . $file->name());
$relpath = str_replace(DOCROOT . $FileManager->getStartLocation(), NULL, dirname($_GET['file']));
redirect($FileManager->baseURL() . 'browse/' . $relpath);
}
}
示例12: handle
function handle($args)
{
common_debug("in oembed api action");
$url = $args['url'];
if (substr(strtolower($url), 0, strlen(common_root_url())) == strtolower(common_root_url())) {
$path = substr($url, strlen(common_root_url()));
$r = Router::get();
$proxy_args = $r->map($path);
if (!$proxy_args) {
// TRANS: Server error displayed in oEmbed action when path not found.
// TRANS: %s is a path.
$this->serverError(sprintf(_('"%s" not found.'), $path), 404);
}
$oembed = array();
$oembed['version'] = '1.0';
$oembed['provider_name'] = common_config('site', 'name');
$oembed['provider_url'] = common_root_url();
switch ($proxy_args['action']) {
case 'shownotice':
$oembed['type'] = 'link';
$id = $proxy_args['notice'];
$notice = Notice::staticGet($id);
if (empty($notice)) {
// TRANS: Server error displayed in oEmbed action when notice not found.
// TRANS: %s is a notice.
$this->serverError(sprintf(_("Notice %s not found."), $id), 404);
}
$profile = $notice->getProfile();
if (empty($profile)) {
// TRANS: Server error displayed in oEmbed action when notice has not profile.
$this->serverError(_('Notice has no profile.'), 500);
}
$authorname = $profile->getFancyName();
// TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date.
$oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), $authorname, common_exact_date($notice->created));
$oembed['author_name'] = $authorname;
$oembed['author_url'] = $profile->profileurl;
$oembed['url'] = $notice->url ? $notice->url : $notice->uri;
$oembed['html'] = $notice->rendered;
break;
case 'attachment':
$id = $proxy_args['attachment'];
$attachment = File::staticGet($id);
if (empty($attachment)) {
// TRANS: Server error displayed in oEmbed action when attachment not found.
// TRANS: %d is an attachment ID.
$this->serverError(sprintf(_('Attachment %s not found.'), $id), 404);
}
if (empty($attachment->filename) && ($file_oembed = File_oembed::staticGet('file_id', $attachment->id))) {
// Proxy the existing oembed information
$oembed['type'] = $file_oembed->type;
$oembed['provider'] = $file_oembed->provider;
$oembed['provider_url'] = $file_oembed->provider_url;
$oembed['width'] = $file_oembed->width;
$oembed['height'] = $file_oembed->height;
$oembed['html'] = $file_oembed->html;
$oembed['title'] = $file_oembed->title;
$oembed['author_name'] = $file_oembed->author_name;
$oembed['author_url'] = $file_oembed->author_url;
$oembed['url'] = $file_oembed->url;
} else {
if (substr($attachment->mimetype, 0, strlen('image/')) == 'image/') {
$oembed['type'] = 'photo';
if ($attachment->filename) {
$filepath = File::path($attachment->filename);
$gis = @getimagesize($filepath);
if ($gis) {
$oembed['width'] = $gis[0];
$oembed['height'] = $gis[1];
} else {
// TODO Either throw an error or find a fallback?
}
}
$oembed['url'] = $attachment->url;
$thumb = $attachment->getThumbnail();
if ($thumb) {
$oembed['thumbnail_url'] = $thumb->url;
$oembed['thumbnail_width'] = $thumb->width;
$oembed['thumbnail_height'] = $thumb->height;
}
} else {
$oembed['type'] = 'link';
$oembed['url'] = common_local_url('attachment', array('attachment' => $attachment->id));
}
}
if ($attachment->title) {
$oembed['title'] = $attachment->title;
}
break;
default:
// TRANS: Server error displayed in oEmbed request when a path is not supported.
// TRANS: %s is a path.
$this->serverError(sprintf(_('"%s" not supported for oembed requests.'), $path), 501);
}
switch ($args['format']) {
case 'xml':
$this->init_document('xml');
$this->elementStart('oembed');
$this->element('version', null, $oembed['version']);
$this->element('type', null, $oembed['type']);
//.........這裏部分代碼省略.........
示例13: merge
public static function merge($path, $name = null, $addon = "", $call = null)
{
$path = is_string($path) && strpos($path, ';') !== false ? explode(';', $path) : (array) $path;
$the_path = ASSET . DS . File::path($name);
$the_path_log = SYSTEM . DS . 'log' . DS . 'asset.' . str_replace(array(ASSET . DS, DS), array("", '__'), $the_path) . '.log';
$is_valid = true;
if (!file_exists($the_path_log)) {
$is_valid = false;
} else {
$the_path_time = explode("\n", file_get_contents($the_path_log));
if (count($the_path_time) !== count($path)) {
$is_valid = false;
} else {
foreach ($the_path_time as $i => $time) {
$p = self::path($path[$i]);
if (!file_exists($p) || (int) filemtime($p) !== (int) $time) {
$is_valid = false;
break;
}
}
}
}
$time = "";
$content = "";
$e = File::E($name);
if (!file_exists($the_path) || !$is_valid) {
if (Text::check($e)->in(array('gif', 'jpeg', 'jpg', 'png'))) {
foreach ($path as $p) {
if (!self::ignored($p)) {
$p = self::path($p);
if (file_exists($p)) {
$time .= filemtime($p) . "\n";
}
}
}
File::write(trim($time))->saveTo($the_path_log);
Image::take($path)->merge()->saveTo($the_path);
} else {
foreach ($path as $p) {
if (!self::ignored($p)) {
$p = self::path($p);
if (file_exists($p)) {
$time .= filemtime($p) . "\n";
$c = file_get_contents($p);
if (strpos(File::B($p), '.min.') === false) {
if (strpos(File::B($the_path), '.min.css') !== false) {
$content .= Converter::detractShell($c) . "\n";
} else {
if (strpos(File::B($the_path), '.min.js') !== false) {
$content .= Converter::detractSword($c) . "\n";
} else {
$content .= $c . "\n\n";
}
}
} else {
$content .= $c . "\n\n";
}
}
}
}
File::write(trim($time))->saveTo($the_path_log);
File::write(trim($content))->saveTo($the_path);
}
}
if (is_null($call)) {
$call = Mecha::alter($e, array('css' => 'stylesheet', 'js' => 'javascript', 'gif' => 'image', 'jpeg' => 'image', 'jpg' => 'image', 'png' => 'image'));
}
return call_user_func_array('self::' . $call, array($the_path, $addon));
}
示例14: scrubHtmlFile
/**
* @return mixed false on failure, HTML fragment string on success
*/
protected function scrubHtmlFile(File $attachment)
{
$path = File::path($attachment->filename);
if (!file_exists($path) || !is_readable($path)) {
common_log(LOG_ERR, "Missing local HTML attachment {$path}");
return false;
}
$raw = file_get_contents($path);
// Normalize...
$dom = new DOMDocument();
if (!$dom->loadHTML($raw)) {
common_log(LOG_ERR, "Bad HTML in local HTML attachment {$path}");
return false;
}
// Remove <script>s or htmlawed will dump their contents into output!
// Note: removing child nodes while iterating seems to mess things up,
// hence the double loop.
$scripts = array();
foreach ($dom->getElementsByTagName('script') as $script) {
$scripts[] = $script;
}
foreach ($scripts as $script) {
common_log(LOG_DEBUG, $script->textContent);
$script->parentNode->removeChild($script);
}
// Trim out everything outside the body...
$body = $dom->saveHTML();
$body = preg_replace('/^.*<body[^>]*>/is', '', $body);
$body = preg_replace('/<\\/body[^>]*>.*$/is', '', $body);
require_once INSTALLDIR . '/extlib/htmLawed/htmLawed.php';
$config = array('safe' => 1, 'deny_attribute' => 'id,style,on*', 'comment' => 1);
// remove comments
$scrubbed = htmLawed($body, $config);
return $scrubbed;
}
示例15: array
if ($request = Request::post()) {
Guardian::checkToken($request['token']);
$info_path = array();
$is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
foreach ($deletes as $file_to_delete) {
$_path = ASSET . DS . $file_to_delete;
$info_path[] = $_path;
File::open($_path)->delete();
}
$P = array('data' => array('files' => $info_path));
Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
Weapon::fire('on_asset_update', array($P, $P));
Weapon::fire('on_asset_destruct', array($P, $P));
Guardian::kick($config->manager->slug . '/asset/1' . $p);
} else {
Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete);
}
Shield::lot('segment', 'asset')->attach('manager', false);
});
/**
* Multiple Asset Killer
* ---------------------
*/
Route::accept($config->manager->slug . '/asset/kill', function ($path = "") use($config, $speak) {
if ($request = Request::post()) {
Guardian::checkToken($request['token']);
if (!isset($request['selected'])) {
Notify::error($speak->notify_error_no_files_selected);
Guardian::kick($config->manager->slug . '/asset/1');
}
$files = array();