function __construct() { $this->cookie = root_path() . 'assets/cookie.txt'; $this->header = array('User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'); Yii::import('application.vendor.simple_html_dom', true); //加载dom解析类 }
function upload($http_url = null) { $url = "upload/" . date('Y') . '/' . date('m') . '/' . date('d'); $dir = root_path() . '/public/' . $url; $temp_dir = root_path() . '/public/upload/temp'; if (!is_dir($dir)) { mkdir($dir, 0775, true); } if (!is_dir($temp_dir)) { mkdir($temp_dir, 0775, true); } if ($http_url) { return $this->_upload($http_url, array('url' => $url, 'dir' => $dir, 'temp_dir' => $temp_dir)); } if (!$_FILES) { return; } foreach ($_FILES as $k => $f) { $tmp_name = $f['tmp_name']; $name = $f['name']; $key = uniqid('', true) . json_encode($f); $name = md5($key) . "." . self::extension($name); $to = $dir . '/' . $name; $old = $temp_dir . '/' . $name; move_uploaded_file($tmp_name, $old); $this->name = $name; $row = $this->_upload_db($old, $to, $url . '/' . $name, $f['size'], $f['type']); $ret[] = $row; } return $row; }
/** * Execute the console command. * * @return int|bool */ public function fire() { $error = $this->app['error']; $files = $this->app['files']; $json_file = base_path('update.json'); $application = $this->app['application']; $bkpDir = root_path('backups'); $project_file = root_path($application->name . '.phar'); $remote = new RemoteFilesystem(); // Check file json update if (file_exists($json_file) != true) { $error->make('%s update configuration not found', $application->title); } $json = json_decode(file_get_contents($json_file)); // Forcar criacao $files->force($bkpDir); // Check for permissions in local backup if (!is_writable($bkpDir)) { $error->make('%s update failed: the "%s" directory used to download the temp file could not be written', $application->title, $bkpDir); } if (!is_writable($project_file)) { $error->make('%s update failed: the "%s" file could not be written', $application->title, $project_file); } // Check version $version_url = trim($json->url->version); $last_version = trim($remote->getContents($version_url, false)); $update_version = $this->argument('version') ?: $last_version; // Validate version sintaxe if (isset($json->versionMask)) { if (preg_match($json->versionMask, $update_version) && $update_version !== $last_version) { $this->error('You can not update to a specific SHA-1 as those phars are not available for download'); return true; } } // Check has updated if (PharInfo::VERSION === $update_version) { $this->info(sprintf('You are already using %s version %s', $application->title, $update_version)); return false; } $temp_file = root_path($application->name . '-temp.phar'); $bkp_file = sprintf('%s/%s-%s%s', $bkpDir, strtr(PharInfo::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', PharInfo::VERSION), self::OLD_INSTALL_EXT); // Atualizar $this->info(sprintf("Updating to version %s.", $update_version)); $file_remote = sprintf('%s/%s/%s', trim($json->url->download), $update_version, basename($project_file)); $remote->copy($file_remote, $temp_file, true); if (!file_exists($temp_file)) { $this->error(sprintf('The download of the new %s version failed for an unexpected reason', $application->title)); return true; } // Trocar arquivo if ($err = $this->setLocalPhar($project_file, $temp_file, $bkp_file)) { $this->error(sprintf('The file is corrupted (%a).', $err->getMessage())); $this->error('Please re-run the self-update command to try again'); return true; } // Disparar evento depois de atualizado \Event::fire('self-update', [$update_version]); return false; }
function current_user_image($width, $height, $shape) { if ($shape == "circle") { return sprintf('<img class="circle" src="%s/views/user/user_picture/%s" width=%d height=%d>', root_path(), current_user('image'), $width, $height); } elseif ($shape == "square") { return sprintf('<img src="%s/views/user/user_picture/%s" width=%d height=%d>', root_path(), current_user('image'), $width, $height); } }
/** * Get the concat'ed commands * * @return string */ private function commands() { $full_path = Path::assemble(root_path(), $this->data->path()); $data = $this->data->toArray(); $data['full_path'] = $full_path; $data['committer'] = User::getCurrent()->toArray(); $commands = []; foreach ($this->getConfig('commands', []) as $command) { $commands[] = Parse::template($command, $data); } return join('; ', $commands); }
public function loadEnvironmentVars() { $handle = fopen(root_path() . '/.env', 'r'); if ($handle) { while (($line = fgets($handle)) !== false) { $var = explode('=', $line); if (!getenv($var[0])) { putenv(trim($line)); } } fclose($handle); } }
/** * Get all of the configuration files for the application. * * @param \Illuminate\Contracts\Foundation\Application $app * @return array */ protected function getConfigurationFiles(Application $app) { $files = []; foreach (Finder::create()->files()->name('*.php')->in($app->configPath()) as $file) { $nesting = $this->getConfigurationNesting($file); $files[$nesting . basename($file->getPathname(), '.php')] = $file->getPathname(); } // Verificar se tem um arquivo de configuracao na pasta do pchar $config_root = root_path('config.php'); if (file_exists($config_root)) { $files['config'] = $config_root; } return $files; }
public function actionIndex() { $id = $_GET['file_id']; if ($id) { $id = base64_decode($id); $id = '/' . $id; } $path = root_path() . '/upload' . $id; $url = base_url() . '/upload' . $id; $name = 'upload' . $id; /** * urlpath生成 */ $arr = explode('/', $name); foreach ($arr as $v) { if ($v != 'upload') { $n .= $v . '/'; } $link = url('image/manage/index', array('file_id' => base64_encode($n))); $urlpath[] = "<a href='" . $link . "'>{$v}</a>"; } if (!function_exists('finfo_open')) { } $dirs = scandir($path); foreach ($dirs as $d) { if ($d != '.' && $d != '..' && $d != '.svn' && $d != '.git' && $d != '.gitignore') { if (is_dir($path . '/' . $d)) { $fullDir = $id . '/' . $d; if (substr($fullDir, 0, 1) == '/') { $fullDir = substr($fullDir, 1); } $listDir[$url . '/' . $id . $d] = array('name' => $d, 'size' => ceil(filesize($path . '/' . $d) / 1024) . ' kb', 'fullDir' => $fullDir, 'time' => date("Y-m-d H:i:s", filemtime($path . '/' . $d))); } else { //取得文件类型 $finfo = finfo_open(FILEINFO_MIME); $mimetype = finfo_file($finfo, $path . '/' . $d); finfo_close($finfo); $mimetype = substr($mimetype, 0, strpos($mimetype, ';')); //判断文件是不是图片 $img = false; if (strpos($mimetype, 'image') !== false) { $img = true; } $listFile[$url . '/' . $d] = array('name' => $d, 'size' => ceil(filesize($path . '/' . $d) / 1024) . ' kb', 'time' => date("Y-m-d H:i:s", filemtime($path . '/' . $d)), 'type' => $mimetype, 'img' => $img); } } } $this->render('index', array('listDir' => $listDir, 'name' => $name, 'urlpath' => $urlpath, 'listFile' => $listFile)); }
function init() { parent::init(); $this->path = root_path() . '/data'; if (!is_dir($this->path)) { mkdir($this->path, 0777, true); } $row = Yii::app()->db->createCommand("SHOW VARIABLES LIKE '%basedir%'")->queryAll(); $this->bin = $row[0]['Value'] . '/bin/'; $dsn = Yii::app()->db->connectionString; $n = explode(';', $dsn); $this->host = substr($n[0], strpos($dsn, '=') + 1); $this->db_name = substr($dsn, strrpos($dsn, '=') + 1); $this->name = Yii::app()->db->username; $this->pwd = Yii::app()->db->password; $dir = $this->path . "/" . $this->db_name . "_"; $this->file = $dir . date('Ymd-H-i-s', time()) . '.sql'; }
function _upload_db($old, $to, $path, $size, $type) { $data = file_get_contents($old); $uniqid = md5($data); $query = new Query(); $query->select('id,path')->from('file')->where(array('uniqid' => $uniqid)); $command = $query->createCommand(); $row = $command->queryRow(); if (!$row) { copy($old, $to); $data = array('path' => $path, 'uniqid' => $uniqid, 'size' => $size, 'type' => $type, 'uid' => $this->uid, 'created' => time(), 'admin' => $this->admin); \Yii::$app->db->createCommand()->insert('file', $data)->execute(); } else { if (!file_exists(root_path() . $row['path'])) { copy($old, root_path() . $row['path']); } } $query = new Query(); $query->select('id,path,type')->from('file')->where(array('uniqid' => $uniqid)); $command = $query->createCommand(); $row = $command->queryRow(); @unlink($old); return $row; }
function img_wh($img) { $a = getimagesize(root_path() . $img); return array('w' => $a[0], 'h' => $a[1]); }
<?php include_once dirname(__FILE__) . "/__settings__.php"; application_settings(__FILE__, null, dirname(dirname(__FILE__))); import("core.Log"); import("core.Flow"); import("core.File"); import("ext.Test"); import("ext.Setup"); header_output_text(); $flow = new Flow(); if ($flow->isVars("class")) { test($flow->inVars("class"), $flow->inVars("method"), $flow->inVars("block")); } else { if (!$flow->isVars("full")) { Test::exec_type(Test::FAIL); } tests(root_path()); }
public function actionIndex() { Yii::import("application.modules.image.lib.Fuel_Image"); $name = $_GET['id']; $ext = substr($name, strrpos($name, '.') + 1); $name = substr($name, 0, strrpos($name, '.')); $l = strpos($name, '='); //生成新的文件名 $new_name = root_path() . '/public/imagine/' . $name . '.' . $ext; //取得encode的数组 $json = substr($name, $l + 1); $name = substr($name, 0, $l); $arr = explode('/', $name); //完整文件名 $file = $name . '.' . $ext; //文件所在路径 $file_path = root_path() . '/public/' . $file; if (!file_exists($file_path)) { //如原文件不存在直接返回 echo "image error"; return; } //生成新文件所存在的路径 $new_dir = FileHelper::dir($new_name); if (!is_dir($new_dir)) { mkdir($new_dir, 0777, true); } $json = cache($json); //操作图片 $imagine = Fuel_Image::load($file_path); foreach ($json as $k => $v) { switch ($k) { case 'resize': $imagine = $imagine->resize($v[0], $v[1], $v[2] ? $v[2] : true, $v[3] ? $v[3] : false); break; case 'crop': //crop(20, 20, 180, 180); $imagine = $imagine->crop($v[0], $v[1], $v[2], $v[3]); break; case 'crop_resize': $imagine = $imagine->crop_resize($v[0], $v[1]); break; case 'rotate': $imagine = $imagine->rotate($v); break; case 'flip': //vertical horizontal both $imagine = $imagine->flip($v); break; case 'watermark': /* * watermark('watermark.ext', "top left", 15); * watermark('watermark.ext', "bottom right"); * watermark('watermark.ext', "center middle"); */ $imagine = $imagine->watermark($v[0], $v['ps'], $v[2]); break; case 'border': //border(10, '#000000'); $imagine = $imagine->border($v[0], $v[1]); break; case 'mask': //mask('mask.ext'); $imagine = $imagine->mask($v); break; case 'rounded': /* * rounded(10, "tl tr"); * rounded(10, null, 0); * rounded(10); */ $imagine = $imagine->rounded($v[0], $v[1], $v[2]); break; case 'grayscale': $imagine = $imagine->grayscale(); break; } } //生成图片 $imagine->save($new_name); echo @file_get_contents($new_name); exit; }
function app_path($path = '') { return root_path("app") . ($path ? DIRECTORY_SEPARATOR . $path : $path); }
function app_path() { return root_path() . '/app/'; }
function absolute_url() { $res = \bmtmgr\config\get('absolute_url_prefix', null); if ($res) { return $res; } $domain = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; $port = $_SERVER['SERVER_PORT']; $https = \array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on'; if ($https && $port != 443 || !$https && $port != 80) { $domain .= ':' . $port; } $root_path = root_path(); if (!endswith($root_path, '/')) { $root_path .= '/'; } return $domain . $root_path; }