本文整理汇总了PHP中FileHelper类的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper类的具体用法?PHP FileHelper怎么用?PHP FileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleFileUpload
/**
* Override parent
*/
function handleFileUpload($fileParameters, $id)
{
$filename = NULL;
if (array_key_exists($this->parameterFile, $_FILES) and array_key_exists('name', $_FILES[$this->parameterFile]) and $_FILES[$this->parameterFile]['name'] != '') {
$fileHelper = new FileHelper();
$filename = $fileHelper->upload($this->fileBasename, $id, $_FILES[$this->parameterFile]);
}
return $filename;
}
示例2: updateTagRelationCache
public static function updateTagRelationCache($manualLock = false)
{
if (!$manualLock) {
self::checkTagRelationCache('lock');
}
try {
$tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php";
$c = new Criteria();
$allTags = TagPeer::doSelect($c);
$content = "<?php \n";
foreach ($allTags as $singleTag) {
$c = new Criteria();
$c->add(TagrelationPeer::TAG_ID, $singleTag->getId());
$tagRelations = TagrelationPeer::doSelect($c);
if ($tagRelations) {
$elementsArr = "array(";
foreach ($tagRelations as $tagRelation) {
$elementsArr .= $tagRelation->getId() . ",";
}
$content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n";
}
}
$content .= "\n?>";
if (FileHelper::writeFile($tagRelationsFile, $content)) {
BackendService::loadTagsRelations();
} else {
echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR);
}
} catch (Exception $e) {
echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR);
}
if (!$manualLock) {
self::checkTagRelationCache('unlock');
}
}
示例3: writeFile
public static function writeFile($file)
{
$supported_image = array('gif', 'jpg', 'jpeg', 'png');
// get the file extension
$extension = $file->getClientOriginalExtension();
// make it lowercase
$extension = strtolower($extension);
// check if it is valid
if (!in_array($extension, $supported_image)) {
// if is not valid, return an error
$obj = new stdClass();
$obj->success = false;
$obj->error = $extension . " is not an valid image type!";
return $obj;
}
// add extension to name
$name = FileHelper::generateRandomString(10);
$name = $name . '.' . $extension;
// create the file
$file->move(__DIR__ . '/images', $name);
// return an success message
$obj = new stdClass();
$obj->success = true;
$obj->message = "Image successfully uploaded!";
$obj->imagePath = $name;
return $obj;
}
示例4: applyTo
public function applyTo($path)
{
return parent::applyTo($path);
$pathMap = $this->pathMap;
if (empty($pathMap)) {
if (($basePath = $this->getBasePath()) === null) {
throw new InvalidConfigException('The "basePath" property must be set.');
}
$pathMap = [Yii::$app->getBasePath() => [$basePath]];
}
$path = FileHelper::normalizePath($path);
foreach ($pathMap as $from => $tos) {
$from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
if (strpos($path, $from) === 0) {
$n = strlen($from);
foreach ((array) $tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
$file = $to . substr($path, $n);
if (is_file($file)) {
return $file;
}
}
}
}
return $path;
}
示例5: build
public function build($runData)
{
// get current backups
$site = $runData->getTemp("site");
$c = new Criteria();
$c->add("site_id", $site->getSiteId());
$sb = DB_SiteBackupPeer::instance()->selectOne($c);
if ($sb) {
if ($sb->getStatus() == "completed") {
// get backup file size
$path = WIKIDOT_ROOT . '/web/files--sites/' . $site->getUnixName() . '/backup/' . $sb->getRand() . '/backup.zip';
// check if file exists
if (!file_exists($path)) {
// in case something failed
DB_SiteBackupPeer::instance()->delete($c);
$sb = null;
} else {
$size = filesize($path);
$sizeFormatted = FileHelper::formatSize($size);
$runData->contextAdd('size', $sizeFormatted);
}
}
}
$runData->contextAdd("site", $site);
$runData->contextAdd("backup", $sb);
}
示例6: actionDownload_client
public function actionDownload_client()
{
$afterDownload = false;
if (isset($_POST['download'])) {
$currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_POST['password'])) {
$afterDownload = true;
$_SESSION['password'] = $_POST['password'];
} else {
Yii::app()->user->setFlash('_error', 'Wrong password!');
}
}
if (isset($_GET['download'])) {
$currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_SESSION['password'])) {
$password = $_SESSION['password'];
$afterDownload = true;
$tmpPath = VIREX_TEMP_PATH;
$variables = array('START_DATE' => date('Y-m-d', strtotime('- 7 day')), 'END_DATE' => date('Y-m-d'), 'USERNAME' => $currentUser['name_usr'], 'PASSWORD' => $password, 'BASE_URL' => VIREX_URL);
// step 1. Create username dir
if (file_exists($tmpPath . '/' . $currentUser['name_usr'])) {
if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc')) {
unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc');
}
if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php')) {
unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php');
}
} else {
mkdir($tmpPath . '/' . $currentUser['name_usr']);
}
$tmpPath = $tmpPath . '/' . $currentUser['name_usr'] . '/';
// step 2. copy originaly files
copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.inc', $tmpPath . 'sampleshare.inc');
copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.php', $tmpPath . 'sampleshare.php');
// step 3. replace variables
$original = file_get_contents($tmpPath . 'sampleshare.php');
foreach ($variables as $k => $v) {
$original = str_replace('<!--' . $k . '--!>', $v, $original);
}
file_put_contents($tmpPath . 'sampleshare.php', $original);
// step 4. create zip archive
$files = array($tmpPath . 'sampleshare.inc', $tmpPath . 'sampleshare.php');
FileHelper::packFiles($files, $tmpPath, 'zip.zip');
// step 5. download contents
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="norman-sampleshare-client-example.zip"');
header('Content-Transfer-Encoding: binary');
readfile($tmpPath . 'zip.zip');
// step 6. clean folder
unlink($tmpPath . 'sampleshare.inc');
unlink($tmpPath . 'sampleshare.php');
unlink($tmpPath . 'zip.zip');
rmdir($tmpPath);
unset($_SESSION['password']);
} else {
Yii::app()->user->setFlash('_error', 'Wrong password!');
}
}
$this->render('download_client', array('afterDownload' => $afterDownload));
}
示例7: actionIndex
/**
* 管理员上传
*/
function actionIndex()
{
$name = $_REQUEST['field'];
if (!$name) {
exit;
}
$file = new FileHelper();
$file->uid = Yii::app()->user->id;
$file->admin = 1;
$rt = $file->upload();
if (!$rt) {
return;
}
$new[] = $rt;
$out = FileHelper::input($new, $name);
echo $out;
exit;
}
示例8: Build
/**
* Populates Source View Model
* @return Source_Vm
*/
public function Build()
{
$fname = FileHelper::getFilename();
$data = FileHelper::getFile(Config::$SongDirectory . $fname);
$viewModel = new Source_Vm();
$viewModel->PageTitle = 'Song Source for "' . $fname . '" ChordPro (CPM)/UkeGeeks File Format';
$viewModel->Body = htmlspecialchars($data);
return $viewModel;
}
示例9: actionPost
public function actionPost()
{
$model = new PostResumeForm(Yii::app()->user->id);
//check max job post
if ($model->getCountUserJobs() < Yii::app()->params['maxResumeJobTitles']) {
if (isset($_POST['PostResumeForm'])) {
$model->attributes = $_POST['PostResumeForm'];
$model->resumeFile = CUploadedFile::getInstance($model, 'resumeFile');
$model->portfolioFile = CUploadedFile::getInstance($model, 'portfolioFile');
if ($model->validate()) {
//checks the number of job titles submitted are within the limit boundry
if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) {
Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles']));
$this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl));
Yii::app()->end();
return;
}
$extension = FileHelper::getExtension($model->resumeFile->name);
if (!empty($model->portfolioFile->name)) {
$extension_PortFolio = FileHelper::getExtension($model->portfolioFile->name);
} else {
$extension_PortFolio = "";
}
//saved file name in the following pattern
// {user_id}cv{time_stamp_string}.{extension}
$fileName = Yii::app()->user->id . 'cv' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension;
if (!empty($extension_PortFolio)) {
$fileName_PortFolio = Yii::app()->user->id . 'pf' . Yii::app()->dateFormatter->format('yyyy-MM-dd_H-mm-ss', time()) . '.' . $extension_PortFolio;
} else {
$fileName_PortFolio = "";
}
if ($model->save(Yii::app()->user->id, $fileName, $fileName_PortFolio)) {
//if(!empty($fileName_PortFolio))
//{
$userFilePath = FileHelper::getFilePath(Yii::getPathOfAlias('site.files') . '/resumes/' . Yii::app()->user->id . '/');
$model->resumeFile->saveAs($userFilePath . $fileName);
if (!empty($fileName_PortFolio)) {
$model->portfolioFile->saveAs($userFilePath . $fileName_PortFolio);
}
Yii::app()->user->setFlash('success', Yii::t('app', 'msg.success.post_resume'));
//}
}
//checks the number of job titles submitted are within the limit boundry
if (count($model->jobTitles) + $model->getCountUserJobs() > Yii::app()->params['maxResumeJobTitles']) {
$this->refresh(true);
} else {
$this->redirect($this->createAbsoluteUrl('index'));
}
}
}
$this->render('post', array('model' => $model));
} else {
Yii::app()->user->setFlash('warning', sprintf(Yii::t('app', 'msg.warning.max_job_titles_exceed'), Yii::app()->params['maxResumeJobTitles']));
$this->redirect(Yii::app()->createAbsoluteUrl($this->getModule()->returnUrl));
}
}
示例10: actionDownload
public function actionDownload($name, $id)
{
if ($name !== null) {
$userFilePath = Yii::getPathOfAlias('site.files') . '/workshops/' . $id;
$userFilePath .= "/" . $name;
if (!FileHelper::outputFile($name, $userFilePath)) {
throw new CHttpException(404, 'File not found');
}
}
}
示例11: fetchDataBasicAuthenticationTmpFile
/**
* Fetches (with curl) a binary or normal file (via http or https) from a remote site as string using HTTPBasicAuth.
* EXAMPLE: FileHelper::fetchDataBasicAuthentication('http://localhost/bli/bla/blum.xml','username','password');
* @param string $url of the data to fetch
* @param string $usr optional username (do not use HTTPBasicAuth if $usr==NULL); default: NULL
* @param string $pass optional password; default: ''
* @return string $filename OR FALSE if HTTP_RESPONSE >= 400. If larger than the PHP memory limit the request should crash - this is actually a security feature?
* @static
*/
function fetchDataBasicAuthenticationTmpFile($url, $postData = null, $usr = NULL, $pass = '')
{
$fn = tempnam("/tmp", "tmpFH");
$data = FileHelper::fetchDataBasicAuthentication($url, $postData, $usr, $pass);
if ($data == FALSE) {
return FALSE;
}
file_put_contents($fn, $data);
return $fn;
}
示例12: _getRealFilePath
/**
* Generate the actual filesystem path for a filekey
*/
protected function _getRealFilePath($filekey, $createDir = true)
{
$filekey = substr(sha1($filekey), 0, 32);
$path = sprintf('%s/%s/', rtrim($this->_filepath, '/'), substr($filekey, 0, self::STUB_KEY_LENGTH));
// ensure directory path exists
if ($createDir && !is_dir($path)) {
FileHelper::createDirectory($path);
}
return $path . $filekey;
}
示例13: getFile
public static function getFile($fileName, $fileType = 'csv')
{
//make sure the file name is unqiue
$fileName = Yii::$app->getRuntimePath() . '/temp/' . $fileName . '.' . strtolower($fileType);
$filePath = dirname($fileName);
if (!is_dir($filePath)) {
FileHelper::createDirectory($filePath, 0777, true);
}
return $fileName;
}
示例14: mapRowToObject
/**
* Map a database row result to object
*
* @param array $row
* @return PressReview
*/
function mapRowToObject($row)
{
$pressReview = new PressReview();
$pressReview->id = $row['id'];
$pressReview->source = stripslashes($row['sourceInfo']);
$pressReview->author = stripslashes($row['author']);
$pressReview->label = stripslashes($row['label']);
$pressReview->url = stripslashes($row['url']);
$pressReview->file = $row['filename'];
$pressReview->date = $row['dateEvent'];
$pressReview->state = $row['state'];
//echo "label : ".$row['label'];
//echo "label : ".stripslashes($row['label']);
//echo "label : ".$pressReview->label;
if ($pressReview->file != NULL) {
$fileHelper = new FileHelper();
$pressReview->fileType = $fileHelper->getFileType($pressReview->file);
}
return $pressReview;
}
示例15: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->uploadRootPath) {
throw new InvalidConfigException('The "savePath" attribute must be set.');
} else {
$this->uploadRootPath = rtrim(Yii::getAlias($this->uploadRootPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if (!file_exists($this->uploadRootPath) && !FileHelper::createDirectory($this->uploadRootPath)) {
throw new InvalidCallException('Directory specified in "savePath" attribute doesn\'t exist or cannot be created.');
}
}
}