本文整理汇总了PHP中Filesystem::makeDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::makeDirectory方法的具体用法?PHP Filesystem::makeDirectory怎么用?PHP Filesystem::makeDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::makeDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param object $connect
* @return void
*/
public function __construct($connect = NULL)
{
if (empty($connect)) {
return false;
}
$this->_db = \App::get('db');
$this->_connect = $connect;
$this->model = $connect->model;
$this->_uid = User::get('id');
$this->params = Plugin::params('projects', 'files');
$this->_logPath = \Components\Projects\Helpers\Html::getProjectRepoPath($this->model->get('alias'), 'logs', false);
if (!is_dir($this->_logPath)) {
Filesystem::makeDirectory($this->_logPath, 0755, true, true);
}
$this->_path = $this->model->repo()->get('path');
}
示例2: makeDirectory
/**
* Make dir
*
* @param array $params
*
* @return array
*/
public function makeDirectory($params = array())
{
$file = isset($params['file']) ? $params['file'] : NULL;
if (!$file instanceof Models\File || $file->get('type') != 'folder') {
return false;
}
if (!$this->get('remote')) {
if (Filesystem::makeDirectory($file->get('fullPath'), 0755, true, true)) {
$this->checkin($params);
return true;
}
}
return false;
}
示例3: getPreview
/**
* Get preview image
*
* @return mixed
*/
public function getPreview($model, $hash = '', $get = 'name', $render = '', $hashed = NULL)
{
if (!$model instanceof Project) {
return false;
}
$image = NULL;
if (!$hashed) {
$hash = $hash ? $hash : $this->get('hash');
$hash = $hash ? substr($hash, 0, 10) : '';
// Determine name and size
switch ($render) {
case 'medium':
$hashed = md5($this->get('name') . '-' . $hash) . '.png';
$maxWidth = 600;
$maxHeight = 600;
break;
case 'thumb':
$hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash, 'png') : NULL;
$maxWidth = 80;
$maxHeight = 80;
break;
default:
$hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash . '-thumb', 'png') : NULL;
$maxWidth = 180;
$maxHeight = 180;
break;
}
}
// Target directory
$target = PATH_APP . DS . trim($model->config()->get('imagepath', '/site/projects'), DS);
$target .= DS . strtolower($model->get('alias')) . DS . 'preview';
$remoteThumb = NULL;
if ($this->get('remoteId') && $this->get('modified')) {
$remoteThumb = substr($this->get('remoteId'), 0, 20) . '_' . strtotime($this->get('modified')) . '.png';
}
if ($hashed && is_file($target . DS . $hashed)) {
// First check locally generated thumbnail
$image = $target . DS . $hashed;
} elseif ($remoteThumb && is_file($target . DS . $remoteThumb)) {
// Check remotely generated thumbnail
$image = $target . DS . $remoteThumb;
// Copy this over as local thumb
if ($hashed && Filesystem::copy($target . DS . $remoteThumb, $target . DS . $hashed)) {
Filesystem::delete($target . DS . $remoteThumb);
}
} else {
// Generate thumbnail locally
if (!file_exists($target)) {
Filesystem::makeDirectory($target, 0755, true, true);
}
// Make sure it's an image file
if (!$this->isImage() || !is_file($this->get('fullPath'))) {
return false;
}
if (!Filesystem::copy($this->get('fullPath'), $target . DS . $hashed)) {
return false;
}
// Resize the image if necessary
$hi = new \Hubzero\Image\Processor($target . DS . $hashed);
$square = $render == 'thumb' ? true : false;
$hi->resize($maxWidth, false, false, $square);
$hi->save($target . DS . $hashed);
$image = $target . DS . $hashed;
}
// Return image
if ($get == 'localPath') {
return str_replace(PATH_APP, '', $image);
} elseif ($get == 'fullPath') {
return $image;
} elseif ($get == 'url') {
return Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&controller=media&media=' . urlencode(basename($image)));
}
return basename($image);
}
示例4: build_path
/**
* Build the path for uploading a resume to
*
* @param integer $uid User ID
* @return mixed False if errors, string otherwise
*/
public function build_path($uid)
{
// Get the configured upload path
$base_path = $this->params->get('webpath', '/site/members');
$base_path = DS . trim($base_path, DS);
$dir = \Hubzero\Utility\String::pad($uid);
$listdir = $base_path . DS . $dir;
if (!is_dir(PATH_APP . $listdir)) {
if (!Filesystem::makeDirectory(PATH_APP . $listdir)) {
return false;
}
}
// Build the path
return $listdir;
}
示例5: publishDataFiles
/**
* Publish supporting database files
*
* @param object $objPD
*
* @return boolean or error
*/
public function publishDataFiles($objPD, $configs)
{
if (!$objPD->id) {
return false;
}
// Get data definition
$dd = json_decode($objPD->data_definition, true);
$files = array();
$columns = array();
foreach ($dd['cols'] as $colname => $col) {
if (isset($col['linktype']) && $col['linktype'] == "repofiles") {
$dir = '';
if (isset($col['linkpath']) && $col['linkpath'] != '') {
$dir = $col['linkpath'];
}
$columns[$col['idx']] = $dir;
}
}
// No files to publish
if (empty($columns)) {
return false;
}
$repoPath = $objPD->source_dir ? $configs->path . DS . $objPD->source_dir : $configs->path;
$csv = $repoPath . DS . $objPD->source_file;
if (file_exists($csv) && ($handle = fopen($csv, "r")) !== FALSE) {
// Check if expert mode CSV
$expert_mode = false;
$col_labels = fgetcsv($handle);
$col_prop = fgetcsv($handle);
$data_start = fgetcsv($handle);
if (isset($data_start[0]) && $data_start[0] == 'DATASTART') {
$expert_mode = true;
}
while ($r = fgetcsv($handle)) {
for ($i = 0; $i < count($col_labels); $i++) {
if (isset($columns[$i])) {
if (isset($r[$i]) && $r[$i] != '') {
$file = $columns[$i] ? $columns[$i] . DS . trim($r[$i]) : trim($r[$i]);
if (file_exists($repoPath . DS . $file)) {
$files[] = $file;
}
}
}
}
}
}
// Copy files from repo to published location
if (!empty($files)) {
foreach ($files as $file) {
if (!file_exists($repoPath . DS . $file)) {
continue;
}
// If parent dir does not exist, we must create it
if (!file_exists(dirname($configs->dataPath . DS . $file))) {
Filesystem::makeDirectory(dirname($configs->dataPath . DS . $file), 0755, true, true);
}
if (Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $file)) {
// Generate thumbnail
$thumb = \Components\Publications\Helpers\Html::createThumbName($file, '_tn', $extension = 'gif');
Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $thumb);
$hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $thumb);
if (count($hi->getErrors()) == 0) {
$hi->resize(180, false, false, false);
$hi->save($configs->dataPath . DS . $thumb);
} else {
return false;
}
// Generate medium image
$med = \Components\Publications\Helpers\Html::createThumbName($file, '_medium', $extension = 'gif');
Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $med);
$hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $med);
if (count($hi->getErrors()) == 0) {
$hi->resize(800, false, false, false);
$hi->save($configs->dataPath . DS . $med);
} else {
return false;
}
}
}
}
}
示例6: downloadresponses
/**
* Generate detailed responses CSV files and zip and offer up as download
*
* @return void
**/
private function downloadresponses()
{
require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'formReport.php';
// Only allow for instructors
if (!$this->course->offering()->section()->access('manage')) {
App::abort(403, 'Sorry, you don\'t have permission to do this');
}
if (!($asset_ids = Request::getVar('assets', false))) {
App::abort(422, 'Sorry, we don\'t know what results you\'re trying to retrieve');
}
$protected = 'site' . DS . 'protected';
$tmp = $protected . DS . 'tmp';
// We're going to temporarily house this in PATH_APP/site/protected/tmp
if (!Filesystem::exists($protected)) {
App::abort(500, 'Missing temporary directory');
}
// Make sure tmp folder exists
if (!Filesystem::exists($tmp)) {
Filesystem::makeDirectory($tmp);
} else {
// Folder was already there - do a sanity check and make sure no old responses zips are lying around
$files = Filesystem::files($tmp);
if ($files && count($files) > 0) {
foreach ($files as $file) {
if (strstr($file, 'responses.zip') !== false) {
Filesystem::delete($tmp . DS . $file);
}
}
}
}
// Get the individual asset ids
$asset_ids = explode('-', $asset_ids);
// Set up our zip archive
$zip = new ZipArchive();
$path = PATH_APP . DS . $tmp . DS . time() . '.responses.zip';
$zip->open($path, ZipArchive::CREATE);
// Loop through the assets
foreach ($asset_ids as $asset_id) {
// Is it a number?
if (!is_numeric($asset_id)) {
continue;
}
// Get the rest of the asset row
$asset = new \Components\Courses\Tables\Asset($this->db);
$asset->load($asset_id);
// Make sure asset is a part of this course
if ($asset->get('course_id') != $this->course->get('id')) {
continue;
}
if ($details = \Components\Courses\Models\FormReport::getLetterResponsesForAssetId($this->db, $asset_id, true, $this->course->offering()->section()->get('id'))) {
$output = implode(',', $details['headers']) . "\n";
if (isset($details['responses']) && count($details['responses']) > 0) {
foreach ($details['responses'] as $response) {
$output .= implode(',', $response) . "\n";
}
}
$zip->addFromString($asset_id . '.responses.csv', $output);
} else {
continue;
}
}
// Close the zip archive handler
$zip->close();
if (is_file($path)) {
// Set up the server
$xserver = new \Hubzero\Content\Server();
$xserver->filename($path);
$xserver->saveas('responses.zip');
$xserver->disposition('attachment');
$xserver->acceptranges(false);
// Serve the file
$xserver->serve();
// Now delete the file
Filesystem::delete($path);
}
// All done!
exit;
}
示例7: doajaxuploadTask
/**
* Upload a file to the profile via AJAX
*
* @return string
*/
public function doajaxuploadTask()
{
//allowed extensions for uplaod
$allowedExtensions = array('png', 'jpe', 'jpeg', 'jpg', 'gif');
//max upload size
$sizeLimit = $this->config->get('maxAllowed', '40000000');
// get the file
if (isset($_GET['qqfile'])) {
$stream = true;
$file = $_GET['qqfile'];
$size = (int) $_SERVER["CONTENT_LENGTH"];
} elseif (isset($_FILES['qqfile'])) {
$stream = false;
$file = $_FILES['qqfile']['name'];
$size = (int) $_FILES['qqfile']['size'];
} else {
echo json_encode(array('error' => Lang::txt('Please select a file to upload')));
return;
}
//check to make sure we have a file and its not too big
if ($size == 0) {
echo json_encode(array('error' => Lang::txt('File is empty')));
return;
}
if ($size > $sizeLimit) {
$max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
echo json_encode(array('error' => Lang::txt('File is too large. Max file upload size is ') . $max));
return;
}
//check to make sure we have an allowable extension
$pathinfo = pathinfo($file);
$filename = $pathinfo['filename'];
$ext = $pathinfo['extension'];
if ($allowedExtensions && !in_array(strtolower($ext), $allowedExtensions)) {
$these = implode(', ', $allowedExtensions);
echo json_encode(array('error' => Lang::txt('File has an invalid extension, it should be one of ' . $these . '.')));
return;
}
// Make the filename safe
$file = Filesystem::clean($file);
// Check project exists
if (!$this->model->exists()) {
echo json_encode(array('error' => Lang::txt('Error loading project')));
return;
}
// Make sure user is authorized (project manager)
if (!$this->model->access('manager')) {
echo json_encode(array('error' => Lang::txt('Unauthorized action')));
return;
}
// Build project image path
$path = PATH_APP . DS . trim($this->config->get('imagepath', '/site/projects'), DS);
$path .= DS . $this->model->get('alias') . DS . 'images';
if (!is_dir($path)) {
if (!Filesystem::makeDirectory($path, 0755, true, true)) {
echo json_encode(array('error' => Lang::txt('COM_PROJECTS_UNABLE_TO_CREATE_UPLOAD_PATH')));
return;
}
}
// Delete older file with same name
if (file_exists($path . DS . $file)) {
Filesystem::delete($path . DS . $file);
}
if ($stream) {
//read the php input stream to upload file
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if (Helpers\Html::virusCheck($temp)) {
echo json_encode(array('error' => Lang::txt('Virus detected, refusing to upload')));
return;
}
//move from temp location to target location which is user folder
$target = fopen($path . DS . $file, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
} else {
move_uploaded_file($_FILES['qqfile']['tmp_name'], $path . DS . $file);
}
// Perform the upload
if (!is_file($path . DS . $file)) {
echo json_encode(array('error' => Lang::txt('COM_PROJECTS_ERROR_UPLOADING')));
return;
} else {
//resize image to max 200px and rotate in case user didnt before uploading
$hi = new \Hubzero\Image\Processor($path . DS . $file);
if (count($hi->getErrors()) == 0) {
$hi->autoRotate();
$hi->resize(200);
$hi->setImageType(IMAGETYPE_PNG);
$hi->save($path . DS . $file);
} else {
echo json_encode(array('error' => $hi->getError()));
//.........这里部分代码省略.........
示例8: uploadTask
/**
* Upload an image
*
* @return void
*/
public function uploadTask()
{
// Check for request forgeries
Request::checkToken();
// Incoming
$id = Request::getInt('id', 0);
if (!$id) {
$this->setError(Lang::txt('COM_STORE_FEEDBACK_NO_ID'));
$this->displayTask($id);
return;
}
// Incoming file
$file = Request::getVar('upload', '', 'files', 'array');
if (!$file['name']) {
$this->setError(Lang::txt('COM_STORE_FEEDBACK_NO_FILE'));
$this->displayTask($id);
return;
}
// Build upload path
$path = PATH_APP . DS . trim($this->config->get('webpath', '/site/store'), DS) . DS . $id;
if (!is_dir($path)) {
if (!\Filesystem::makeDirectory($path)) {
$this->setError(Lang::txt('COM_STORE_UNABLE_TO_CREATE_UPLOAD_PATH'));
$this->displayTask($id);
return;
}
}
// Make the filename safe
$file['name'] = \Filesystem::clean($file['name']);
$file['name'] = str_replace(' ', '_', $file['name']);
require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'imghandler.php';
// Perform the upload
if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
$this->setError(Lang::txt('COM_STORE_ERROR_UPLOADING'));
} else {
$ih = new ImgHandler();
// Do we have an old file we're replacing?
if ($curfile = Request::getVar('currentfile', '')) {
// Remove old image
if (file_exists($path . DS . $curfile)) {
if (!\Filesystem::delete($path . DS . $curfile)) {
$this->setError(Lang::txt('COM_STORE_UNABLE_TO_DELETE_FILE'));
$this->displayTask($id);
return;
}
}
// Get the old thumbnail name
$curthumb = $ih->createThumbName($curfile);
// Remove old thumbnail
if (file_exists($path . DS . $curthumb)) {
if (!\Filesystem::delete($path . DS . $curthumb)) {
$this->setError(Lang::txt('COM_STORE_UNABLE_TO_DELETE_FILE'));
$this->displayTask($id);
return;
}
}
}
// Create a thumbnail image
$ih->set('image', $file['name']);
$ih->set('path', $path . DS);
$ih->set('maxWidth', 80);
$ih->set('maxHeight', 80);
$ih->set('cropratio', '1:1');
$ih->set('outputName', $ih->createThumbName());
if (!$ih->process()) {
$this->setError($ih->getError());
}
}
// Push through to the image view
$this->displayTask($id);
}
示例9: publishAttachment
/**
* Publish file attachment
*
* @param object $objPA
* @param object $pub
* @param object $configs
* @param boolean $update force update of file
*
* @return boolean or error
*/
public function publishAttachment($objPA, $pub, $configs, $update = 0)
{
// Create pub version path
if (!is_dir($configs->pubPath)) {
if (!Filesystem::makeDirectory($configs->pubPath, 0755, true, true)) {
$this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNABLE_TO_CREATE_PATH'));
return false;
}
}
$file = $objPA->path;
$copyFrom = isset($configs->copyFrom) ? $configs->copyFrom : $configs->path . DS . $file;
$copyTo = $this->getFilePath($file, $objPA->id, $configs, $objPA->params);
// Copy
if (is_file($copyFrom)) {
// If parent dir does not exist, we must create it
if ($configs->dirHierarchy && !file_exists(dirname($copyTo))) {
Filesystem::makeDirectory(dirname($copyTo), 0755, true, true);
}
if (!is_file($copyTo) || $update) {
Filesystem::copy($copyFrom, $copyTo);
}
}
// Store content hash
if (is_file($copyTo)) {
$md5hash = hash_file('sha256', $copyTo);
$objPA->content_hash = $md5hash;
// Create hash file
$hfile = $copyTo . '.hash';
if (!is_file($hfile)) {
$handle = fopen($hfile, 'w');
fwrite($handle, $md5hash);
fclose($handle);
chmod($hfile, 0644);
}
$objPA->store();
// Produce thumbnail (if applicable)
if ($configs->handler && $configs->handler->getName() == 'imageviewer') {
$configs->handler->makeThumbnail($objPA, $pub, $configs);
}
} else {
return false;
}
return true;
}
示例10: renderPageImages
/**
* Create images
*
* @return void
*/
public function renderPageImages()
{
try {
if (!$this->exists()) {
$this->setError(Lang::txt('No pages exist for nonexistent certificate.'));
return false;
}
$base = $this->path('system');
if (!file_exists($base)) {
if (!\Filesystem::makeDirectory($base)) {
$this->setError(Lang::txt('Unable to create directory.'));
return false;
}
}
$fname = $base . DS . $this->get('filename', 'certificate.pdf');
// Get the number of images for our for-loop
$im = new Imagick($fname);
$num = $im->getNumberImages();
// Now actually do the image creation and cropping based on min margin
for ($pages = 0; $pages < $num; ++$pages) {
$im = new Imagick();
$im->setResolution(300, 300);
$im->readImage($fname . '[' . $pages . ']');
$im->setImageFormat('png');
$im->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
$im->writeImage($base . DS . ($pages + 1) . '.png');
}
return true;
} catch (ImagickException $ex) {
// nothing
$this->setError($ex->getMessage());
return false;
}
}
示例11: defined
* @license http://opensource.org/licenses/MIT MIT
*/
// No direct access
defined('_HZEXEC_') or die;
$database = App::get('db');
$jt = new \Components\Jobs\Tables\JobType($database);
$jc = new \Components\Jobs\Tables\JobCategory($database);
$profile = \Hubzero\User\Profile::getInstance($this->seeker->uid);
$jobtype = $jt->getType($this->seeker->sought_type, strtolower(Lang::txt('COM_JOBS_TYPE_ANY')));
$jobcat = $jc->getCat($this->seeker->sought_cid, strtolower(Lang::txt('COM_JOBS_CATEGORY_ANY')));
$title = Lang::txt('COM_JOBS_ACTION_DOWNLOAD') . ' ' . $this->seeker->name . ' ' . ucfirst(Lang::txt('COM_JOBS_RESUME'));
// Get the configured upload path
$base_path = DS . trim($this->params->get('webpath', '/site/members'), DS);
$path = $base_path . DS . \Hubzero\Utility\String::pad($this->seeker->uid);
if (!is_dir(PATH_APP . $path)) {
if (!Filesystem::makeDirectory(PATH_APP . $path)) {
$path = '';
}
}
$resume = is_file(PATH_APP . $path . DS . $this->seeker->filename) ? $path . DS . $this->seeker->filename : '';
?>
<div class="aboutme<?php
echo $this->seeker->mine && $this->list ? ' mine' : '';
echo isset($this->seeker->shortlisted) && $this->seeker->shortlisted ? ' shortlisted' : '';
?>
">
<div class="thumb">
<img src="<?php
echo $profile->getPicture();
?>
" alt="<?php
示例12: receiptTask
//.........这里部分代码省略.........
$r->colors = str_replace(' ', '', $r->colors);
$r->selectedcolor = trim($selections->get('color', ''));
$r->colors = preg_split('/,/', $r->colors);
}
} else {
App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('Order empty, cannot generate receipt'), 'error');
return;
}
$customer = User::getInstance($row->uid);
} else {
App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('Need order ID to issue a receipt'), 'error');
return;
}
// Include needed libraries
// require_once(JPATH_COMPONENT . DS . 'helpers' . DS . 'receipt.pdf.php');
// Build the link displayed
$sef = Route::url('index.php?option=' . $this->_option);
if (substr($sef, 0, 1) == '/') {
$sef = substr($sef, 1, strlen($sef));
}
$webpath = str_replace('/administrator/', '/', Request::base() . $sef);
$webpath = str_replace('//', '/', $webpath);
if (isset($_SERVER['HTTPS'])) {
$webpath = str_replace('http:', 'https:', $webpath);
}
if (!strstr($webpath, '://')) {
$webpath = str_replace(':/', '://', $webpath);
}
//require_once(PATH_CORE . DS . 'libraries/tcpdf/tcpdf.php');
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$receipt_title = $this->config->get('receipt_title') ? $this->config->get('receipt_title') : 'Your Order';
$hubaddress = array();
$hubaddress[] = $this->config->get('hubaddress_ln1') ? $this->config->get('hubaddress_ln1') : '';
$hubaddress[] = $this->config->get('hubaddress_ln2') ? $this->config->get('hubaddress_ln2') : '';
$hubaddress[] = $this->config->get('hubaddress_ln3') ? $this->config->get('hubaddress_ln3') : '';
$hubaddress[] = $this->config->get('hubaddress_ln4') ? $this->config->get('hubaddress_ln4') : '';
$hubaddress[] = $this->config->get('hubaddress_ln5') ? $this->config->get('hubaddress_ln5') : '';
$hubaddress[] = $this->config->get('hubemail') ? $this->config->get('hubemail') : '';
$hubaddress[] = $this->config->get('hubphone') ? $this->config->get('hubphone') : '';
$headertext_ln1 = $this->config->get('headertext_ln1') ? $this->config->get('headertext_ln1') : '';
$headertext_ln2 = $this->config->get('headertext_ln2') ? $this->config->get('headertext_ln2') : Config::get('sitename');
$footertext = $this->config->get('footertext') ? $this->config->get('footertext') : 'Thank you for contributions to our HUB!';
$receipt_note = $this->config->get('receipt_note') ? $this->config->get('receipt_note') : '';
// Get front-end template name
$sql = "SELECT template FROM `#__template_styles` WHERE `client_id`=0 AND `home`=1";
$this->database->setQuery($sql);
$tmpl = $this->database->loadResult();
// set default header data
$pdf->SetHeaderData(NULL, 0, strtoupper($receipt_title) . ' - #' . $id, NULL, array(84, 94, 124), array(146, 152, 169));
$pdf->setFooterData(array(255, 255, 255), array(255, 255, 255));
// set header and footer fonts
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(10);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// Set font
$pdf->SetFont('dejavusans', '', 11, '', true);
$pdf->AddPage();
// HTML content
$this->view->setLayout('receipt');
$this->view->hubaddress = $hubaddress;
$this->view->headertext_ln1 = $headertext_ln1;
$this->view->headertext_ln2 = $headertext_ln2;
$this->view->receipt_note = $receipt_note;
$this->view->receipt_title = $receipt_title;
$this->view->option = $this->_option;
$this->view->url = $webpath;
$this->view->customer = $customer;
$this->view->row = $row;
$this->view->orderitems = $orderitems;
$html = $this->view->loadTemplate();
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------
$dir = PATH_APP . DS . 'site' . DS . 'store' . DS . 'temp';
$tempFile = $dir . DS . 'receipt_' . $id . '.pdf';
if (!is_dir($dir)) {
if (!\Filesystem::makeDirectory($dir)) {
throw new Exception(Lang::txt('Failed to create folder to store receipts'), 500);
}
}
// Close and output PDF document
$pdf->Output($tempFile, 'F');
if (is_file($tempFile)) {
$xserver = new Server();
$xserver->filename($tempFile);
$xserver->serve_inline($tempFile);
exit;
} else {
App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('There was an error creating a receipt'), 'error');
return;
}
return;
}
示例13: save
/**
* Save incoming
*
* @return boolean
*/
public function save($element, $elementId, $pub, $blockParams, $toAttach = array())
{
// Incoming selections
if (empty($toAttach)) {
$selections = Request::getVar('selecteditems', '');
$toAttach = explode(',', $selections);
}
// Get configs
$configs = $this->getConfigs($element, $elementId, $pub, $blockParams);
// Cannot make changes
if ($configs->freeze) {
return false;
}
// Nothing to change
if (empty($toAttach)) {
return false;
}
// Create new version path
if (!is_dir($configs->dataPath)) {
if (!Filesystem::makeDirectory($configs->dataPath, 0755, true, true)) {
$this->_parent->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNABLE_TO_CREATE_PATH'));
return false;
}
}
// Counters
$i = 0;
$a = 0;
// Attach/refresh each selected item
foreach ($toAttach as $identifier) {
if (!trim($identifier)) {
continue;
}
$a++;
$ordering = $i + 1;
if ($this->addAttachment($identifier, $pub, $configs, User::get('id'), $elementId, $element, $ordering)) {
$i++;
}
}
// Success
if ($i > 0 && $i == $a) {
$message = $this->get('_message') ? $this->get('_message') : Lang::txt('Selection successfully saved');
$this->set('_message', $message);
}
return true;
}
示例14: uploadTask
/**
* Upload a file or create a new folder
*
* @return void
*/
public function uploadTask()
{
// Check for request forgeries
Request::checkToken();
// Incoming directory (this should be a path built from a resource ID and its creation year/month)
$listdir = Request::getVar('listdir', '', 'post');
if (!$listdir) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR'));
$this->displayTask();
return;
}
// Incoming sub-directory
$subdir = Request::getVar('dirPath', '', 'post');
// Build the path
$path = Utilities::buildUploadPath($listdir, $subdir);
// Are we creating a new folder?
$foldername = Request::getVar('foldername', '', 'post');
if ($foldername != '') {
// Make sure the name is valid
if (preg_match("/[^0-9a-zA-Z_]/i", $foldername)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_INVALID_CHARACTERS'));
} else {
if (!is_dir($path . DS . $foldername)) {
if (!\Filesystem::makeDirectory($path . DS . $foldername)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
}
} else {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_EXISTS'));
}
}
// Directory created
} else {
// Make sure the upload path exist
if (!is_dir($path)) {
if (!\Filesystem::makeDirectory($path)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
$this->displayTask();
return;
}
}
// Incoming file
$file = Request::getVar('upload', '', 'files', 'array');
if (!$file['name']) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_FILE'));
$this->displayTask();
return;
}
// Make the filename safe
$file['name'] = \Filesystem::clean($file['name']);
// Ensure file names fit.
$ext = \Filesystem::extension($file['name']);
$file['name'] = str_replace(' ', '_', $file['name']);
if (strlen($file['name']) > 230) {
$file['name'] = substr($file['name'], 0, 230);
$file['name'] .= '.' . $ext;
}
// Perform the upload
if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UPLOADING'));
} else {
// File was uploaded
// Was the file an archive that needs unzipping?
$batch = Request::getInt('batch', 0, 'post');
if ($batch) {
//build path
$path = rtrim($path, DS) . DS;
$escaped_file = escapeshellarg($path . $file['name']);
//determine command to uncompress
switch ($ext) {
case 'gz':
$cmd = "tar zxvf {$escaped_file} -C {$path}";
break;
case 'tar':
$cmd = "tar xvf {$escaped_file} -C {$path}";
break;
case 'zip':
default:
$cmd = "unzip -o {$escaped_file} -d {$path}";
}
//unzip file
if ($result = shell_exec($cmd)) {
// Remove original archive
\Filesystem::delete($path . $file['name']);
// Remove MACOSX dirs if there
if (\Filesystem::exists($path . '__MACOSX')) {
\Filesystem::deleteDirectory($path . '__MACOSX');
}
//remove ._ files
$dotFiles = \Filesystem::files($path, '._[^\\s]*', true, true);
foreach ($dotFiles as $dotFile) {
\Filesystem::delete($dotFile);
}
}
}
}
//.........这里部分代码省略.........
示例15: _createImportFilespace
/**
* Method to create import filespace if needed
*
* @param object $import Models\Import
* @return boolean
*/
private function _createImportFilespace(Models\Import $import)
{
// upload path
$uploadPath = $import->fileSpacePath();
// if we dont have a filespace, create it
if (!is_dir($uploadPath)) {
\Filesystem::makeDirectory($uploadPath, 0775);
}
// all set
return true;
}