本文整理匯總了PHP中File::ext方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::ext方法的具體用法?PHP File::ext怎麽用?PHP File::ext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類File
的用法示例。
在下文中一共展示了File::ext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: File
function admin_upload_photo($image = null)
{
$path = "img\\products\\";
$dir = WWW_ROOT . $path;
//trenutna lokacija slike
$imageTmp = $image['Product']['file']['tmp_name'];
$imageName = $image['Product']['file']['name'];
$file = new File($imageTmp);
//preverjanje koncnic za sliko
$ext = $file->ext();
/*
if($ext != 'jpg' || $ext != 'jpeg' || $ext != 'png' || $ext != 'gif'){
pr('Wrong extension - ');
print_r($file);
die;
return false;
}*/
$fileData = $file->read();
$file->close();
//zapis v nov fajl
$file = new File($dir . $imageName, true);
$file->write($fileData);
$file->close();
//nastavitev pd_image na ime slike (ker je se vedno array())
return $imageName;
}
示例2: admin_view
public function admin_view($id = null)
{
$filename = WWW_ROOT . FilesController::FILE_ROOT . DS . implode(DS, $this->request->params['pass']) . "." . $this->request->params['ext'];
debug($filename);
$file = new File($filename, false);
if (!$file->exists()) {
throw new NotFoundException(__('File not found: ') . $file->path);
}
debug($file->name);
debug($file->ext());
debug($file->Folder()->path);
$this->viewClass = 'Media';
$params = array('id' => $file->name, 'name' => $file->name(), 'download' => false, 'extension' => $file->ext(), 'path' => $file->Folder()->path . DS);
$this->set($params);
//$this->set('fee', $this->Fee->read(null, $id));
}
示例3: read
/**
* Reads a MagicDb from various formats
*
* @var $magicDb mixed Can be an array containing the db, a magic db as a string, or a filename pointing to a magic db in .db or magic.db.php format
* @return boolean Returns false if reading / validation failed or true on success.
* @access private
*/
public function read($magicDb = null)
{
if (!is_string($magicDb) && !is_array($magicDb)) {
return false;
}
if (is_array($magicDb) || strpos($magicDb, '# FILE_ID DB') === 0) {
$data = $magicDb;
} else {
$File = new File($magicDb);
if (!$File->exists()) {
return false;
}
if ($File->ext() == 'php') {
include $File->pwd();
$data = $magicDb;
} else {
// @TODO: Needs test coverage
$data = $File->read();
}
}
$magicDb = $this->toArray($data);
if (!$this->validates($magicDb)) {
return false;
}
return !!($this->db = $magicDb);
}
示例4: findByChildren
/**
* ImageHelper::findByExtention()
*
* @param mixed $extention
* @return
*/
function findByChildren($children = array())
{
$images = Configure::read('CoreImages.images');
if (empty($children[1])) {
return $this->Html->image(Configure::read('CoreImages.path') . 'folders/' . $images['folders']['empty'], $this->settings + array('title' => __('Empty Folder'), 'alt' => __('Empty Folder')));
}
App::import('File');
foreach ($children[1] as $child) {
$File = new File($child);
$ext = $File->ext();
if (!isset($data[$ext])) {
$data[$ext] = 0;
continue;
}
$data[$ext]++;
unset($File);
}
$highest = 0;
$_ext = '';
foreach ($data as $k => $v) {
if ($v > $highest) {
$highest = $v;
$_ext = $k;
}
}
return $this->findByExtention($_ext);
}
示例5: format
/**
* Determine the format of given database
*
* @param mixed $db
*/
function format($db)
{
if (empty($db)) {
return null;
}
if (is_array($db)) {
return 'Array';
}
if (!is_string($db)) {
return null;
}
$File = new File($db);
if ($File->exists()) {
if ($File->ext() === 'php') {
return 'PHP';
}
$File->open('rb');
$head = $File->read(4096);
if (preg_match('/^(\\d{2}:)?[-\\w.+]*\\/[-\\w.+]+:[\\*\\.a-zA-Z0-9]*$/m', $head)) {
return 'Freedesktop Shared MIME-info Database';
} elseif (preg_match('/^[-\\w.+]*\\/[-\\w.+]+\\s+[a-zA-Z0-9]*$/m', $head)) {
return 'Apache Module mod_mime';
}
}
return null;
}
示例6: file_extension
protected function file_extension($value, $params)
{
$allowed_exts = $params['extension'];
$f = new File($value['name']);
$problems = array();
if (is_array($allowed_exts)) {
if (!in_array(strtolower($f->ext()), $allowed_exts)) {
$problems[] = 'A extensão do arquivo deve ser ' . join(',', $allowed_exts);
}
} else {
if ($f->ext() != $allowed_exts) {
$problems[] = 'A extensão do arquivo deve ser ' . $allowed_exts;
}
}
if (count($problems) == 0) {
return false;
}
return $problems;
}
示例7: _evaluate
/**
* Evalute a view file, rendering it's contents
*
* @return string The output
*/
protected function _evaluate($viewFile, $dataForView)
{
$file = new File($viewFile);
if ($file->ext() != self::$extension) {
return parent::_evaluate($viewFile, $dataForView);
}
$file = $this->_createRenderedView($viewFile);
$content = parent::_evaluate($file, $dataForView);
$this->_deleteRenderedView($file);
return $content;
}
示例8: File
/**
*
* @param $data
* @return bool
*/
function validate_file($data)
{
try {
$file_name = $data['upload']['name'];
if (!empty($file_name)) {
$tempFile = new File($file_name);
$ext = $tempFile->ext();
$ext = strtolower($ext);
$types = array("gif", "jpg", "jpeg", "png", "pjpeg", "x-png", "x-tiff");
$val = in_array($ext, $types, true);
if ($val) {
return true;
}
return false;
}
return true;
} catch (Exception $exception) {
echo $exception->getMessage();
}
}
示例9: __new__
protected function __new__($file_path)
{
$this->cmd = def("arbo.io.FFmpeg@cmd", "/usr/local/bin/ffmpeg");
$info = Command::error(sprintf("%s -i %s", $this->cmd, $file_path));
$file = new File($file_path);
$this->name = $file->oname();
$this->ext = $file->ext();
$this->filename = $file_path;
$this->framerate = preg_match("/frame rate: .+ -> ?([\\d\\.]+)/", $info, $match) ? (double) $match[1] : null;
$this->bitrate = preg_match("/bitrate: (\\d+)/", $info, $match) ? (double) $match[1] : null;
$this->duration = preg_match("/Duration: ([\\d\\:\\.]+)/", $info, $match) ? Date::parse_time($match[1]) : null;
if (preg_match("/Video: (.+)/", $info, $match)) {
$video = explode(",", $match[1]);
if (isset($video[0])) {
$this->video_codec = trim($video[0]);
}
if (isset($video[1])) {
$this->format = trim($video[1]);
}
if (isset($video[2])) {
list($this->width, $this->height) = explode("x", trim($video[2]));
if (preg_match("/(\\d+) .+DAR (\\d+\\:\\d+)/", $this->height, $match)) {
list(, $this->height, $this->aspect) = $match;
}
}
if (empty($this->aspect) && isset($video[3])) {
$this->aspect = preg_match("/DAR (\\d+\\:\\d+)/", $video[3], $match) ? $match[1] : null;
}
}
if (preg_match("/Audio: (.+)/", $info, $match)) {
$audio = explode(",", $match[1]);
if (isset($audio[0])) {
$this->audio_codec = trim($audio[0]);
}
if (isset($audio[1])) {
$this->samplerate = preg_match("/\\d+/", $audio[1], $match) ? $match[0] : null;
}
}
$this->frame_count = ceil($this->duration * $this->framerate);
}
示例10: ShortCode
public static function ShortCode($arguments)
{
extract($arguments);
// Obtain json file on public folder
$id = $id ? $id : '';
$json = '';
$galleryFile = ROOT_DIR . '/public/gallery/gallery.json';
if (File::exists($galleryFile)) {
$json = json_decode(File::getContent($galleryFile), true);
} else {
die('OOps Whrere is media.json file!');
}
$num = 0;
$photos = File::scan(ROOT_DIR . '/public/gallery/galleries/' . $id);
$img = Url::getBase() . '/public/gallery/galleries/' . $id . '/' . File::name($photos[0]) . '.' . File::ext($photos[0]);
// get plugin info
//var_dump(json_encode(Config::get('plugins.gallery'),true));
$template = Template::factory(PLUGINS_PATH . '/gallery/templates/');
$template->setOptions(['strip' => false]);
// show template
return $template->fetch('slide.tpl', ['id' => $id, 'title' => $json[$id]['title'], 'description' => $json[$id]['desc'], 'first' => $img, 'photos' => $photos]);
}
示例11: uploadPhoto
public function uploadPhoto($data)
{
$validtypes = array('png', 'gif', 'jpg', 'jpeg', 'pjpeg', 'bmp');
$filetype = substr($data['photo']['type'], 6);
if (in_array($filetype, $validtypes)) {
$this->deletePhoto();
// Delete previous photo.
$tmp_file = new File($data['photo']['tmp_name']);
if ($filetype == 'jpeg' || $filetype == 'pjpeg') {
$filetype = 'jpg';
}
$filename = 'img/users/' . AuthComponent::user('username') . '.' . $filetype;
$file = new File($filename, true);
$file->write($tmp_file->read());
// Write new photo.
if ($file->executable() || !in_array($file->ext(), $validtypes)) {
$file->delete();
return false;
}
return true;
}
return false;
}
示例12: import
static function import()
{
#>> import modules
foreach (func_get_args() as $unit) {
# get the real file name
$unit = ABS_PATH . str_replace('.', '/', $unit);
# get the dir from the unit name
$dir = dirname($unit);
# imports all the php scripts from the dir
if (substr($unit, -1) == '*' && ($dh = opendir($dir))) {
while (($file = readdir($dh)) !== false) {
if (File::ext($file) == 'php') {
# import the script
require_once $dir . '/' . $file;
}
}
closedir($dh);
} else {
if (is_file($unit .= '.php')) {
require_once $unit;
}
}
}
}
示例13: format
/**
* Determine the format of given database
*
* @param mixed $db
*/
function format($db)
{
if (empty($db)) {
return null;
}
if (is_array($db)) {
return 'Array';
}
if (!is_string($db)) {
return null;
}
$File = new File($db);
if ($File->exists()) {
if ($File->ext() === 'php') {
return 'PHP';
}
$File->open('rb');
$head = $File->read(4096);
if (substr($head, 0, 12) === "MIME-Magic\n") {
return 'Freedesktop Shared MIME-info Database';
}
if (preg_match('/^(\\>*)(\\d+)\\t+(\\S+)\\t+([\\S^\\040]+)\\t*([-\\w.\\+]+\\/[-\\w.\\+]+)*\\t*(\\S*)$/m', $head)) {
return 'Apache Module mod_mime_magic';
}
}
return null;
}
示例14: file
/**
* Setup for display or download the given file.
*
* If $_SERVER['HTTP_RANGE'] is set a slice of the file will be
* returned instead of the entire file.
*
* ### Options keys
*
* - name: Alternate download name
* - download: If `true` sets download header and forces file to be downloaded rather than displayed in browser
*
* @param string $path Path to file. If the path is not an absolute path that resolves
* to a file, `APP` will be prepended to the path.
* @param array $options Options See above.
* @return void
* @throws NotFoundException
*/
public function file($path, $options = array())
{
$options += array('name' => null, 'download' => null);
if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) {
throw new NotFoundException(__d('cake_dev', 'The requested file contains `..` and will not be read.'));
}
if (!is_file($path)) {
$path = APP . $path;
}
$file = new File($path);
if (!$file->exists() || !$file->readable()) {
if (Configure::read('debug')) {
throw new NotFoundException(__d('cake_dev', 'The requested file %s was not found or not readable', $path));
}
throw new NotFoundException(__d('cake', 'The requested file was not found'));
}
$extension = strtolower($file->ext());
$download = $options['download'];
if ((!$extension || $this->type($extension) === false) && $download === null) {
$download = true;
}
$fileSize = $file->size();
if ($download) {
$agent = env('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
$contentType = 'application/octet-stream';
} elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/force-download';
}
if (!empty($contentType)) {
$this->type($contentType);
}
if ($options['name'] === null) {
$name = $file->name;
} else {
$name = $options['name'];
}
$this->download($name);
$this->header('Content-Transfer-Encoding', 'binary');
}
$this->header('Accept-Ranges', 'bytes');
$httpRange = env('HTTP_RANGE');
if (isset($httpRange)) {
$this->_fileRange($file, $httpRange);
} else {
$this->header('Content-Length', $fileSize);
}
$this->_clearBuffer();
$this->_file = $file;
}
示例15: cleanGeneratedCss
/**
* Clean the generated CSS files
*
* @return array
*/
public function cleanGeneratedCss()
{
$this->_removeCacheKey('sass_compiled');
// Cleaned files that we will return
$cleanedFiles = array();
foreach ($this->_sassFolders as $key => $sassFolder) {
foreach ($sassFolder->find() as $file) {
$file = new File($file);
if (($file->ext() == 'sass' || $file->ext() == 'scss') && substr($file->name, 0, 2) !== '._') {
$sassFile = $sassFolder->path . DS . $file->name;
$cssFile = $this->_cssFolders[$key]->path . DS . str_replace(array('.sass', '.scss'), '.css', $file->name);
if (file_exists($cssFile)) {
unlink($cssFile);
$cleanedFiles[] = $cssFile;
}
}
}
}
// Remove all cache files at once
if (is_dir($this->_cacheFolder)) {
@closedir($this->_cacheFolder);
$folder = new Folder($this->_cacheFolder);
$folder->delete();
unset($folder);
$cleanedFiles[] = $this->_cacheFolder . DS . '*';
}
mkdir($this->_cacheFolder);
return $cleanedFiles;
}