本文整理汇总了PHP中Filesystem::copy方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::copy方法的具体用法?PHP Filesystem::copy怎么用?PHP Filesystem::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file
/**
* Aplicar template de um arquivo único.
*
* @param $file
* @param $target
*/
public function file($file, $target)
{
// Verificar se template existe na lista
if ($this->files->exists($file) != true) {
error('Template %s não foi encontrado', $file);
}
$this->outpath = '';
$this->filters = [$target];
// Criar diretório destino
$path = $this->files->path($target);
$this->files->force($path);
// Copiar arquivo
$this->files->copy($file, $target);
return $this;
}
示例2: processThumb
public function processThumb($imgsrc, $_id, $isUrl = true)
{
$_id = empty($_id) ? $this->_id : $_id;
$storage = Yii::app()->params['feed_path'];
$temp = Yii::app()->params['temp'];
$fileInfo = explode('.', $imgsrc);
$fileType = $fileInfo[count($fileInfo) - 1];
$fileName = 'tmp_' . $_id . "." . $fileType;
$tmpFile = $temp . DS . $fileName;
if ($isUrl) {
$res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
} else {
$fileSystem = new Filesystem();
$res_get_file = $fileSystem->copy($imgsrc, $tmpFile);
}
if (file_exists($tmpFile)) {
$fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
/*$fileSystem = new Filesystem();
$copy = $fileSystem->copy($tmpFile,$fileDest);*/
$width = Yii::app()->params['profile_image']['thumb']['width'];
$height = Yii::app()->params['profile_image']['thumb']['height'];
$resizeObj = new ResizeImage($tmpFile);
$rs = $resizeObj->resizeImage($width, $height, 0);
$res = $resizeObj->saveImage($fileDest, 100);
if ($resizeObj) {
$feed = self::model()->findByPk(new MongoId($_id));
$fileDest = str_replace($storage, '', $fileDest);
$feed->thumb = $fileDest;
$res = $feed->save();
return $res;
}
} else {
throw new Exception("create file temp error!", 7);
}
}
示例3: beforeGetContentBody
protected function beforeGetContentBody()
{
$sn = time();
$i = 0;
$tmpFile = $temp = Yii::app()->params['temp'];
$storage = Yii::app()->params['feed_path'];
$cdn = Yii::app()->params['cdn_url'];
$contentParttern = $this->config['content_pattern'];
foreach ($this->html->find("{$contentParttern} img") as $e) {
$imgSrc = $e->src;
if (!empty($imgSrc)) {
$fileInfo = explode('.', $imgSrc);
$fileType = $fileInfo[count($fileInfo) - 1];
$fileName = 'tmp_' . $sn . $i . "." . $fileType;
$sfile = $tmpFile . DS . $fileName;
$res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
if ($res_get_file && file_exists($sfile)) {
$fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
$fileSystem = new Filesystem();
$copy = $fileSystem->copy($sfile, $fileDest);
if ($copy) {
echo $fileDest . "\n";
$fileDestUrl = str_replace($storage, $cdn, $fileDest);
$fileDestUrl = str_replace(DS, "/", $fileDestUrl);
echo $fileDestUrl . "\n";
$e->src = $fileDestUrl;
echo 'replace file content success' . "\n";
} else {
echo 'replace file content error' . "\n";
}
}
$i++;
}
}
}
示例4: moveDefaultTemplate
private function moveDefaultTemplate()
{
$this->log('Moving default template...');
$fileDir = $this->container->getParameter('claroline.param.files_directory');
$defaultTemplate = $this->container->getParameter('claroline.param.default_template');
$newTemplateDir = $fileDir . '/templates';
$newTemplate = $newTemplateDir . '/default.zip';
$fs = new Filesystem();
$fs->mkdir($newTemplateDir);
$fs->copy($defaultTemplate, $newTemplate);
}
示例5: _compile
//.........这里部分代码省略.........
$resource = $this->_connect->loadRemoteResource($this->_remoteService, $this->model->get('owned_by_user'), $file->get('remoteId'));
$cExt = $tex ? 'tex' : \Components\Projects\Helpers\Google::getGoogleImportExt($resource['mimeType']);
$cExt = in_array($cExt, array('tex', 'jpeg')) ? $cExt : 'pdf';
$url = \Components\Projects\Helpers\Google::getDownloadUrl($resource, $cExt);
// Get data
$view->data = $this->_connect->sendHttpRequest($this->_remoteService, $this->model->get('owned_by_user'), $url);
} elseif ($file->exists()) {
$view->data = $file->isImage() ? NULL : $file->contents();
} else {
$this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_NO_DATA'));
}
// LaTeX file?
if ($tex && !empty($view->data)) {
// Clean up data from Windows characters - important!
$view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data);
// Compile and get path to PDF
$contentFile = $compiler->compileTex($file->get('fullPath'), $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase);
// Read log (to show in case of error)
$logFile = $tempBase . '.log';
if (file_exists(PATH_APP . $outputDir . DS . $logFile)) {
$view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile);
}
if (!$contentFile) {
$this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED'));
}
} elseif ($file->get('converted') && !empty($view->data)) {
$tempBase = \Components\Projects\Helpers\Google::getImportFilename($file->get('name'), $cExt);
// Write content to temp file
$this->_connect->fetchFile($view->data, $tempBase, PATH_APP . $outputDir);
$contentFile = $tempBase;
} elseif (!$this->getError()) {
// Make sure we can handle preview of this type of file
if ($file->get('ext') == 'pdf' || $file->isImage() || !$file->isBinary()) {
Filesystem::copy($file->get('fullPath'), PATH_APP . $outputDir . DS . $tempBase);
$contentFile = $tempBase;
}
}
$url = $this->model->link('files');
$url .= $this->repo->isLocal() ? '' : '&repo=' . $this->repo->get('name');
$url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : '';
// Parse output
if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) {
// Get compiled content mimetype
$cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile);
// Is image?
if (strpos($cType, 'image/') !== false) {
// Fix up object width & height
list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile);
$xRatio = $view->oWidth / $width;
$yRatio = $view->oHeight / $height;
if ($xRatio * $height < $view->oHeight) {
// Resize the image based on width
$view->oHeight = ceil($xRatio * $height);
} else {
// Resize the image based on height
$view->oWidth = ceil($yRatio * $width);
}
}
// Download compiled file?
if ($download) {
$pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile);
// Serve up file
$server = new \Hubzero\Content\Server();
$server->filename(PATH_APP . $outputDir . DS . $contentFile);
$server->disposition('attachment');
$server->acceptranges(false);
示例6: 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);
}
示例7: 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;
}
}
}
}
}
示例8: moveFile
private function moveFile($id, $type, $fileSource)
{
try {
$pathUpload = Yii::app()->params['storage']['radioDir'] . DS . "channel" . DS;
$filePath = $pathUpload . $id . ".png";
$fileSystem = new Filesystem();
$fileSystem->copy($fileSource, $filePath);
//$fileSystem->remove($fileSource);
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例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: actionIndex
public function actionIndex()
{
$my_file = Yii::app()->params['storage'] . DS . 'meme_page.txt';
$handle = fopen($my_file, 'r');
$page = fread($handle, filesize($my_file));
$page = intval($page);
for ($i = $page; $i < $page + 2; $i++) {
echo $url = 'http://www.lolhappens.com/page/' . $i;
echo "\n";
$html = file_get_html($url);
$content = $html->find(".content-wrap", 0);
foreach ($content->find(".social-bar") as $e) {
$e->outertext = "";
}
//echo $content;exit;
$storage = Yii::app()->params['storage'];
$temp = Yii::app()->params['temp'];
$j = 0;
foreach ($content->find(".hentry") as $e) {
$title = $e->find(".post-title h2 a", 0)->plaintext;
$link = $e->find(".post-title h2 a", 0)->href;
$imageUrl = $img = $e->find(".post-content p img", 0)->src;
$fileInfo = explode('.', $img);
$fileType = $fileInfo[count($fileInfo) - 1];
$fileName = 's_' . $j . '_' . $i . time() . "." . $fileType;
$fileDesc = $storage . DS . $fileName;
$tmpFile = $temp . DS . $fileName;
if (!$this->isExists($link)) {
$res_get_file = FileRemote::getFromUrl($img, $tmpFile);
if ($res_get_file && file_exists($tmpFile)) {
$meme = new MemeLink();
$meme->title = trim($title);
$meme->code = trim($link);
$meme->link = trim($link);
$meme->content = $imageUrl;
$meme->type = 'image';
$meme->source = 'lolhappens.com';
$meme->status = 0;
$meme->created_datetime = date('Y-m-d H:i:s');
if ($meme->save()) {
//copy file
$storage = Yii::app()->params['meme_path'];
$mId = $meme->_id;
$fileDest = StorageHelper::generalStoragePath($meme->_id, $fileType, $storage);
$fileSystem = new Filesystem();
$copy = $fileSystem->copy($tmpFile, $fileDest);
if ($copy) {
echo 'Copy file success' . "\n";
$img = str_replace($storage, '', $fileDest);
$img = str_replace(DS, '_', $img);
$meme->img = $img;
$meme->save();
} else {
if ($meme->delete()) {
echo 'deleted:' . $mId . "\n";
}
}
echo 'save success!' . "\n";
echo $meme->_id . "\n";
} else {
$error = $meme->getErrors();
var_dump($error);
}
}
} else {
continue;
}
echo 'File source:' . $img . "<br />";
echo 'File dest:' . $fileDesc . "<br />";
$j++;
}
}
//write page end
$data = $i;
$handle = fopen($my_file, 'w') or die('Cannot open file: ' . $my_file);
fwrite($handle, $data);
fclose($handle);
}
示例11: _addFromExtracted
/**
* Add files to repo from extracted archive
*
* @return boolean
*/
protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
{
$reserved = isset($params['reserved']) ? $params['reserved'] : array();
$dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
$extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
// check for viruses - scans the directory for efficency
$command = "clamscan -i --no-summary --block-encrypted -r " . $extractPath;
exec($command, $output, $virus_status);
$virusChecked = FALSE;
if ($virus_status == 0) {
$virusChecked = TRUE;
} else {
Filesystem::deleteDirectory($extractPath);
$this->setError('The antivirus software has rejected your files.');
return false;
}
$z = 0;
foreach ($extracted as $e) {
$fileinfo = pathinfo($e);
$a_dir = $fileinfo['dirname'];
$a_dir = str_replace($extractPath . DS, '', $a_dir);
// Skip certain system files
if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
continue;
}
$file = $fileinfo['basename'];
$size = filesize($e);
// Run some checks, stop in case of a problem
if (!$this->_check($file, $e, $size, $available, $virusChecked)) {
return false;
}
// Clean up filename
$safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
$safe_dir = trim($safe_dir, DS);
$safe_file = Filesystem::clean($file);
// Strips out temporary path
if (strpos($safe_dir, 'tmp/') !== FALSE) {
$parts = explode('/', $safe_dir);
$safe_dir = str_replace($parts[0] . '/', '', $safe_dir);
$safe_dir = str_replace($parts[1] . '/', '', $safe_dir);
}
$skipDir = false;
if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
$skipDir = true;
}
$safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
$localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
$where = $target . DS . $safeName;
$exists = is_file($where) ? true : false;
// Provision directory
if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
// File object
$localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
$fileObject = new Models\File(trim($localDirPath), $this->get('path'));
$fileObject->set('type', 'folder');
$params['file'] = $fileObject;
$params['replace'] = false;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
// Strips out temporary path
if (strpos($safeName, 'tmp/') !== FALSE) {
$parts = explode('/', $safeName);
$safeName = str_replace($parts[0] . '/', '', $safeName);
$safeName = str_replace($parts[1] . '/', '', $safeName);
}
// Copy file into project
if (Filesystem::copy($e, $target . DS . $safeName)) {
// File object
$fileObject = new Models\File(trim($localPath), $this->get('path'));
$params['file'] = $fileObject;
$params['replace'] = $exists;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
return $z;
}
示例12: _addFromExtracted
/**
* Add files to repo from extracted archive
*
* @return boolean
*/
protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
{
$reserved = isset($params['reserved']) ? $params['reserved'] : array();
$dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
$extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
$z = 0;
foreach ($extracted as $e) {
$fileinfo = pathinfo($e);
$a_dir = $fileinfo['dirname'];
$a_dir = str_replace($extractPath . DS, '', $a_dir);
// Skip certain system files
if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
continue;
}
$file = $fileinfo['basename'];
$size = filesize($e);
// Run some checks, stop in case of a problem
if (!$this->_check($file, $e, $size, $available)) {
return false;
}
// Clean up filename
$safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
$safe_dir = trim($safe_dir, DS);
$safe_file = Filesystem::clean($file);
$skipDir = false;
if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
$skipDir = true;
}
$safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
$localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
$where = $target . DS . $safeName;
$exists = is_file($where) ? true : false;
// Provision directory
if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
// File object
$localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
$fileObject = new Models\File(trim($localDirPath), $this->get('path'));
$fileObject->set('type', 'folder');
$params['file'] = $fileObject;
$params['replace'] = false;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
// Copy file into project
if (Filesystem::copy($e, $target . DS . $safeName)) {
// File object
$fileObject = new Models\File(trim($localPath), $this->get('path'));
$params['file'] = $fileObject;
$params['replace'] = $exists;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
return $z;
}
示例13: createImage
function createImage($model, $image_path)
{
if (file_exists($image_path)) {
$fileSystem = new Filesystem();
$s0Path = $model->getAvatarPath($model->id, "s0", false);
// Origin
$s1Path = $model->getAvatarPath($model->id, "s1", false);
// Resize
$s2Path = $model->getAvatarPath($model->id, "s2", false);
// Thumb
$fileSystem->mkdirs(dirname($s0Path));
$fileSystem->mkdirs(dirname($s1Path));
$fileSystem->mkdirs(dirname($s2Path));
list($width, $height) = getimagesize($image_path);
$imgCrop = new ImageCrop($image_path, 0, 0, $width, $height);
$fileSystem->copy($image_path, $s0Path);
$imgCrop->resizeFix($s1Path, 690, 250);
$imgCrop->resizeFix($s2Path, 100, 100);
$fileSystem->remove($image_path);
}
}
示例14: doWork
/**
* This method allows you to do any additional work beyond unpacking
* the files that is required. This could include work such as downloading
* and unpacking an archive.
*
* The following are some of the methods available to you in this file:
* $this->curlFile($url, $destFolder)
* $this->move($src, $dest)
* $this->unzip($file, $destFolder)
*/
public function doWork()
{
$fs = new Filesystem();
// Ensure tmp working dir exists
$tmp = $this->mRootPath . "\\tmp";
$this->log("Creating temporary build directory: " . $tmp);
$fs->mkdir($tmp);
if ($this->p->get('source') != '' && $fs->exists($this->p->get('source'))) {
// Use WordPress codebase from source parameter
$this->log("Copying WordPress from " . $this->p->get('source'));
$fs->copy($this->p->get('source'), $this->mAppRoot);
} else {
// Download and unpack WordPress
$this->log('Downloading WordPress');
$file = $this->curlFile(WP_URL, $tmp);
$this->log('Extracting WordPress');
$this->unzip($file, $tmp);
$this->log('Moving WordPress files to ' . $this->mAppRoot);
$fs->move("{$tmp}\\wordpress", $this->mAppRoot);
}
// Download and unpack DB abstraction layer
$this->log('Downloading Database Abstraction Layer');
$file = $this->curlFile(DB_ABSTRACTION_URL, $tmp);
$this->log('Extracting Database Abstraction Layer');
$this->unzip($file, $tmp);
$this->log('Moving Database Abstraction Layer files to ' . $this->mAppRoot . "\\wp-content\\mu-plugins");
$fs->copy("{$tmp}\\wordpress-database-abstraction\\wp-db-abstraction\\db.php", $this->mAppRoot . "\\wp-content\\db.php");
$fs->move("{$tmp}\\wordpress-database-abstraction", $this->mAppRoot . "\\wp-content\\mu-plugins");
// Download and unpack Azure Storage Plugin
$this->log('Downloading Azure Storage Plugin');
$file = $this->curlFile(WAZ_STORAGE_URL, $tmp);
$this->log('Extracting Azure Storage Plugin');
$this->unzip($file, $tmp);
$this->log('Moving Azure Storage Plugin files to ' . $this->mAppRoot . "\\wp-content\\plugins");
$fs->move("{$tmp}\\windows-azure-storage", $this->mAppRoot . "\\wp-content\\plugins\\windows-azure-storage");
if ($this->p->get('WP_ALLOW_MULTISITE') && $this->p->get('WP_ALLOW_MULTISITE') != 'false') {
$fs->mkdir($this->mAppRoot . "\\wp-content\\blogs.dir");
unlink("{$this->mAppRoot}.config");
if ($this->p->get('SUBDOMAIN_INSTALL')) {
copy($this->mAppRoot . "\\resources\\Web-network-subdomains.config", $this->mAppRoot . "\\Web.config");
} else {
copy($this->mAppRoot . "\\resources\\Web-network-subfolders.config", $this->mAppRoot . "\\Web.config");
}
}
// Remove tmp build folder
$fs->rm($tmp);
$fs->rm($this->mRootPath . "/Params.class.php");
$fs->rm($this->mRootPath . "/FileSystem.class.php");
$this->updateWpConfig();
echo "\n\nCongratulations! You now have a brand new Windows Azure WordPress project at " . $this->mRootPath . "\n";
}
示例15: makeThumbnail
/**
* Make thumb
*
* @return void
*/
public function makeThumbnail($row, $pub, $configs)
{
// Make sure we got config
if (!$this->_config) {
$this->getConfig();
}
$fpath = $this->getFilePath($row->path, $row->id, $configs, $row->params);
$thumbName = \Components\Publications\Helpers\Html::createThumbName(basename($fpath), $this->_config->params->thumbSuffix, $this->_config->params->thumbFormat);
$thumbPath = $configs->pubPath . DS . $thumbName;
// No file found
if (!is_file($fpath)) {
return;
}
// Check if image
if (!getimagesize($fpath)) {
return false;
}
$md5 = hash_file('sha256', $fpath);
// Create/update thumb if doesn't exist or file changed
if (!is_file($thumbPath) || $md5 != $row->content_hash) {
Filesystem::copy($fpath, $thumbPath);
$hi = new \Hubzero\Image\Processor($thumbPath);
if (count($hi->getErrors()) == 0) {
$hi->resize($this->_config->params->thumbWidth, false, true, true);
$hi->save($thumbPath);
} else {
return false;
}
}
return true;
}