本文整理汇总了PHP中File::url方法的典型用法代码示例。如果您正苦于以下问题:PHP File::url方法的具体用法?PHP File::url怎么用?PHP File::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: notifyBackupFile
function notifyBackupFile($user, $fileName)
{
$fileUrl = File::url($fileName);
$body = sprintf(_m("The backup file you requested is ready for download.\n\n" . "%s\n" . "Thanks for your time,\n", "%s\n"), $fileUrl, common_config('site', 'name'));
$headers = _mail_prepare_headers('offlinebackup', $user->nickname, $user->nickname);
mail_to_user($user, _('Backup file ready for download'), $body, $headers);
}
示例2: testURLConstruction
public function testURLConstruction()
{
$root = new Root();
$root->setScheme('s://');
$root->addDirectory($dir = new Directory('dir'));
$dir->addDirectory($dir = new Directory('dir'));
$dir->addFile($file = new File('file'));
$this->assertEquals('s://dir/dir/file', $file->url());
}
示例3: url
public static function url($path_origin)
{
$config = Config::get();
$path = self::path($path_origin);
$url = File::url($path);
if (strpos($path, ROOT) === false) {
return strpos($url, '://') !== false ? Filter::apply('asset:url', $url . ($config->resource_versioning && strpos($url, $config->url) === 0 ? '?' . sprintf(ASSET_VERSION_FORMAT, filemtime($path)) : ""), $path_origin) : false;
}
return file_exists($path) ? Filter::apply('asset:url', $url . ($config->resource_versioning ? '?' . sprintf(ASSET_VERSION_FORMAT, filemtime($path)) : ""), $path_origin) : false;
}
示例4: url
public static function url($source)
{
$config = Config::get();
$source = Filter::colon('asset:source', $source);
$path = Filter::colon('asset:path', self::path($source, false));
$url = File::url($path);
if ($path && strpos($path, ROOT) === false) {
return strpos($url, '://') !== false || strpos($url, '//') === 0 ? Filter::colon('asset:url', $url, $source) : false;
}
return $path && file_exists($path) ? Filter::colon('asset:url', $url, $source) : false;
}
示例5: storeFile
function storeFile()
{
$file = new File();
$file->filename = $this->filename;
$file->url = File::url($this->filename);
$filepath = File::path($this->filename);
$file->size = filesize($filepath);
$file->date = time();
$file->mimetype = $this->mimetype;
$file_id = $file->insert();
if (!$file_id) {
common_log_db_error($file, "INSERT", __FILE__);
throw new ClientException(_('There was a database error while saving your file. Please try again.'));
}
return $file;
}
示例6: handle
/**
* Handle the request
*
* @return void
*/
protected function handle()
{
parent::handle();
$profile = $this->user->getProfile();
$base64img = $this->img;
if (stristr($base64img, 'image/jpeg')) {
$base64img_mime = 'image/jpeg';
} elseif (stristr($base64img, 'image/png')) {
// should convert to jpg here!!
$base64img_mime = 'image/png';
}
$base64img = str_replace('data:image/jpeg;base64,', '', $base64img);
$base64img = str_replace('data:image/png;base64,', '', $base64img);
$base64img = str_replace(' ', '+', $base64img);
$base64img_hash = md5($base64img);
$base64img = base64_decode($base64img);
$base64img_basename = basename('bg');
$base64img_filename = File::filename($profile, $base64img_basename, $base64img_mime);
$base64img_path = File::path($base64img_filename);
$base64img_success = file_put_contents($base64img_path, $base64img);
$base64img_mimetype = MediaFile::getUploadedMimeType($base64img_path, $base64img_filename);
$mediafile = new MediaFile($profile, $base64img_filename, $base64img_mimetype);
$imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
$imagefile->resizeTo(File::path($mediafile->filename), array('width' => 1280, 'height' => 1280, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
$result['url'] = File::url($mediafile->filename);
Profile_prefs::setData($profile, 'qvitter', 'background_image', $result['url']);
$this->initDocument('json');
$this->showJsonObjects($result);
$this->endDocument('json');
}
示例7: storeThumbnail
/**
* Generate and store a thumbnail image for the uploaded file, if applicable.
*
* @return File_thumbnail or null
*/
function storeThumbnail()
{
if (substr($this->mimetype, 0, strlen('image/')) != 'image/') {
// @fixme video thumbs would be nice!
return null;
}
try {
$image = new ImageFile($this->fileRecord->id, File::path($this->filename));
} catch (Exception $e) {
// Unsupported image type.
return null;
}
$outname = File::filename($this->user->getProfile(), 'thumb-' . $this->filename, $this->mimetype);
$outpath = File::path($outname);
$maxWidth = common_config('attachments', 'thumb_width');
$maxHeight = common_config('attachments', 'thumb_height');
list($width, $height) = $this->scaleToFit($image->width, $image->height, $maxWidth, $maxHeight);
$image->resizeTo($outpath, $width, $height);
File_thumbnail::saveThumbnail($this->fileRecord->id, File::url($outname), $width, $height);
}
示例8: formatAttachment
/**
* Format the attachment placeholder img with the final version.
*
* @param DOMElement $img
* @param MediaFile $media
*/
private function formatAttachment($img, $media)
{
$parent = $img->parentNode;
$dom = $img->ownerDocument;
$link = $dom->createElement('a');
$link->setAttribute('href', $media->fileurl);
$link->setAttribute('title', File::url($media->filename));
if ($this->isEmbeddable($media)) {
// Fix the the <img> attributes and wrap the link around it...
$this->insertImage($img, $media);
$parent->replaceChild($link, $img);
//it dies in here?!
$link->appendChild($img);
} else {
// Not an image? Replace it with a text link.
$link->setAttribute('rel', 'external');
$link->setAttribute('class', 'attachment');
$link->setAttribute('id', 'attachment-' . $media->fileRecord->id);
$text = $dom->createTextNode($media->shortUrl());
$link->appendChild($text);
$parent->replaceChild($link, $img);
}
}
示例9: kick
/**
* ============================================================
* URL REDIRECTION
* ============================================================
*
* -- CODE: ---------------------------------------------------
*
* Guardian::kick('manager/login');
*
* ------------------------------------------------------------
*
*/
public static function kick($path = "")
{
$path = Converter::url(File::url($path));
$path = Filter::apply('guardian:kick', $path);
$G = array('data' => array('url' => $path));
Session::set('url_origin', Config::get('url_current'));
Weapon::fire('before_kick', array($G, $G));
header('Location: ' . $path);
exit;
}
示例10: handle
/**
* Handle the request
*
* @return void
*/
protected function handle()
{
parent::handle();
$profile = $this->user->getProfile();
// see if we have regular uploaded image data
try {
$mediafile = MediaFile::fromUpload('banner', $profile);
} catch (NoUploadedMediaException $e) {
// if not we may have base64 data
$img = $this->img;
if (stristr($img, 'image/jpeg')) {
$img_mime = 'image/jpeg';
} elseif (stristr($img, 'image/png')) {
// should convert to jpg here!!
$img_mime = 'image/png';
}
// i don't remember why we had to do this
$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$img = base64_decode($img, true);
try {
$img_filename = File::filename($profile, 'cover', $img_mime);
$img_path = File::path($img_filename);
$img_success = file_put_contents($img_path, $img);
$img_mimetype = MediaFile::getUploadedMimeType($img_path, $img_filename);
$mediafile = new MediaFile($profile, $img_filename, $img_mimetype);
} catch (Exception $e) {
$this->clientError($e, 400);
}
}
if (!$mediafile instanceof MediaFile) {
$this->clientError(_('Could not process image data.'), 400);
}
// maybe resize
$width = $this->cropW;
$height = $this->cropH;
$scale = 1;
if ($width > 1200) {
$scale = 1200 / $width;
} elseif ($height > 600) {
$scale = 600 / $height;
}
$width = round($width * $scale);
$height = round($height * $scale);
// crop
try {
$imagefile = new ImageFile($mediafile->fileRecord->id, File::path($mediafile->filename));
$imagefile->resizeTo(File::path($mediafile->filename), array('width' => $width, 'height' => $height, 'x' => $this->cropX, 'y' => $this->cropY, 'w' => $this->cropW, 'h' => $this->cropH));
$result['url'] = File::url($mediafile->filename);
} catch (Exception $e) {
$this->clientError(_('The image could not be resized and cropped. ' . $e), 422);
}
// save in profile_prefs
try {
Profile_prefs::setData($profile, 'qvitter', 'cover_photo', $result['url']);
} catch (ServerException $e) {
$this->clientError(_('The image could not be resized and cropped. ' . $e), 422);
}
// return json
$this->initDocument('json');
$this->showJsonObjects($result);
$this->endDocument('json');
}
示例11: showLogo
/**
* Show configured logo.
*
* @return nothing
*/
function showLogo()
{
$this->elementStart('address', array('id' => 'site_contact', 'class' => 'vcard'));
if (Event::handle('StartAddressData', array($this))) {
if (common_config('singleuser', 'enabled')) {
$user = User::singleUser();
$url = common_local_url('showstream', array('nickname' => $user->nickname));
} else {
$url = common_local_url('public');
}
$this->elementStart('a', array('class' => 'url home bookmark', 'href' => $url));
if (StatusNet::isHTTPS()) {
$logoUrl = common_config('site', 'ssllogo');
if (empty($logoUrl)) {
// if logo is an uploaded file, try to fall back to HTTPS file URL
$httpUrl = common_config('site', 'logo');
if (!empty($httpUrl)) {
$f = File::staticGet('url', $httpUrl);
if (!empty($f) && !empty($f->filename)) {
// this will handle the HTTPS case
$logoUrl = File::url($f->filename);
}
}
}
} else {
$logoUrl = common_config('site', 'logo');
}
if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
// This should handle the HTTPS case internally
$logoUrl = Theme::path('logo.png');
}
if (!empty($logoUrl)) {
$this->element('img', array('class' => 'logo photo', 'src' => $logoUrl, 'alt' => common_config('site', 'name')));
}
$this->text(' ');
$this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
$this->elementEnd('a');
Event::handle('EndAddressData', array($this));
}
$this->elementEnd('address');
}
示例12:
<div class="grid col-9">
<div class="row">
<form action="" method="post" enctype="multipart/form-data" >
<p><?php
if (isset($confirm) && $confirm > 0) {
echo "Modificación exitosa";
}
?>
</p>
<h3>Ingrese la imagen de fondo</h3>
<input type="file" name="background" accept="image/*">
<br>
<br>
<input type="submit" value="Enviar" class="btn">
<input type="hidden" name="add" val="">
</form>
<h3>Preview</h3>
<img src="<?php
echo File::url(Config::option('bgtestimonios'));
?>
" alt="Preview imagen testimonios">
</div>
</div>
</div>
</div>
<?php
require "template/footer.php";
示例13:
</p>
<?php
}
?>
<p>
<?php
if ($e === 'cache') {
?>
<?php
echo Form::hidden('name', File::url($the_name));
?>
<?php
} else {
?>
<?php
echo Form::text('name', Guardian::wayback('name', File::url($the_name)), $speak->manager->placeholder_file_name);
?>
<?php
}
?>
<?php
if (strpos($config->url_path, '/repair/file:') === false) {
?>
<?php
echo Jot::button('construct', $speak->create);
?>
<?php
} else {
?>
<?php
echo Jot::button('action', $is_text ? $speak->update : $speak->rename);
示例14: storeFile
protected function storeFile()
{
$filepath = File::path($this->filename);
if (!empty($this->filename) && $this->filehash === null) {
// Calculate if we have an older upload method somewhere (Qvitter) that
// doesn't do this before calling new MediaFile on its local files...
$this->filehash = hash_file(File::FILEHASH_ALG, $filepath);
if ($this->filehash === false) {
throw new ServerException('Could not read file for hashing');
}
}
try {
$file = File::getByHash($this->filehash);
// We're done here. Yes. Already. We assume sha256 won't collide on us anytime soon.
return $file;
} catch (NoResultException $e) {
// Well, let's just continue below.
}
$fileurl = File::url($this->filename);
$file = new File();
$file->filename = $this->filename;
$file->urlhash = File::hashurl($fileurl);
$file->url = $fileurl;
$file->filehash = $this->filehash;
$file->size = filesize($filepath);
if ($file->size === false) {
throw new ServerException('Could not read file to get its size');
}
$file->date = time();
$file->mimetype = $this->mimetype;
$file_id = $file->insert();
if ($file_id === false) {
common_log_db_error($file, "INSERT", __FILE__);
// TRANS: Client exception thrown when a database error was thrown during a file upload operation.
throw new ClientException(_('There was a database error while saving your file. Please try again.'));
}
// Set file geometrical properties if available
try {
$image = ImageFile::fromFileObject($file);
$orig = clone $file;
$file->width = $image->width;
$file->height = $image->height;
$file->update($orig);
// We have to cleanup after ImageFile, since it
// may have generated a temporary file from a
// video support plugin or something.
// FIXME: Do this more automagically.
if ($image->getPath() != $file->getPath()) {
$image->unlink();
}
} catch (ServerException $e) {
// We just couldn't make out an image from the file. This
// does not have to be UnsupportedMediaException, as we can
// also get ServerException from files not existing etc.
}
return $file;
}
示例15: url
static function url($filename)
{
// TODO: Store thumbnails in their own directory and don't use File::url here
return File::url($filename);
}