本文整理汇总了PHP中Folder::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::make方法的具体用法?PHP Folder::make怎么用?PHP Folder::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::make方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: redactor__upload
public function redactor__upload()
{
if (!Auth::getCurrentMember()) {
exit("Invalid Request");
}
$path = Request::get('path');
$is_image = Request::get('is_image');
if (isset($path)) {
$dir = Path::tidy(ltrim($path, '/') . '/');
if (isset($_POST['subfolder'])) {
$dir .= $_POST['subfolder'] . '/';
}
Folder::make($dir);
$file_type = strtolower($_FILES['file']['type']);
$file_info = pathinfo($_FILES['file']['name']);
// pull out the filename bits
$filename = $file_info['filename'];
$ext = $file_info['extension'];
// build filename
$file = $dir . $filename . '.' . $ext;
// check for dupes
if (File::exists($file)) {
$file = BASE_PATH . '/' . $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
}
if (!Folder::isWritable($dir)) {
Log::error('Upload failed. Directory "' . $dir . '" is not writable.', 'redactor');
echo json_encode(array('error' => "Redactor: Upload directory not writable."));
die;
}
if ($is_image && ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg')) {
if (Request::get('resize', false)) {
$image = Image::make($_FILES['file']['tmp_name']);
$width = Request::get('width', null);
$height = Request::get('height', null);
$ratio = Request::get('ratio', true);
$upsize = Request::get('upsize', false);
$quality = Request::get('quality', '75');
$image->resize($width, $height, $ratio, $upsize)->save($file, $quality);
} else {
move_uploaded_file($_FILES['file']['tmp_name'], $file);
}
} else {
move_uploaded_file($_FILES['file']['tmp_name'], $file);
}
$return = array('filelink' => Path::toAsset($file));
echo stripslashes(json_encode($return));
} else {
echo json_encode(array('error' => "Redactor: Upload directory not set."));
}
}
示例2: loadCache
/**
* Loads the content cache into the local cache variable if not done yet
*
* @param boolean $force Force this to load?
* @return void
* @throws Exception
*/
public static function loadCache($force = false)
{
if (!$force && self::$cache_loaded) {
return;
}
self::$cache_loaded = true;
self::$cache = unserialize(File::get(Path::tidy(BASE_PATH . "/_cache/_app/content/content.php")));
if (!is_array(self::$cache)) {
// Attempt to make the cache folder. It doesn't hurt to try.
Folder::make(BASE_PATH . '/_cache/');
// something has gone wrong, log a message and set to an empty array
self::$cache = array();
Log::fatal('Could not find or access your cache. Try checking your file permissions.', 'core', 'ContentService');
throw new Exception('Could not find or access your cache. Try checking your file permissions.');
}
}
示例3: redactor__upload
public function redactor__upload()
{
if (!Statamic_Auth::get_current_user()) {
exit("Invalid Request");
}
$path = Request::get('path');
if (isset($path)) {
$dir = Path::tidy(ltrim($path, '/') . '/');
if (isset($_POST['subfolder'])) {
$dir .= $_POST['subfolder'] . '/';
}
Folder::make($dir);
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg') {
$file_info = pathinfo($_FILES['file']['name']);
// pull out the filename bits
$filename = $file_info['filename'];
$ext = $file_info['extension'];
// build filename
$file = $dir . $filename . '.' . $ext;
// check for dupes
if (File::exists($file)) {
$file = $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
}
if (!Folder::isWritable($dir)) {
Log::error('Upload failed. Directory "' . $dir . '" is not writable.', 'redactor');
echo json_encode(array('error' => "Redactor: Upload directory not writable."));
die;
}
copy($_FILES['file']['tmp_name'], $file);
// display file
$array = array('filelink' => Config::getSiteRoot() . $file);
echo stripslashes(json_encode($array));
} else {
echo json_encode(array('error' => "Redactor: Could not find directory: '{$dir}'"));
}
} else {
echo json_encode(array('error' => "Redactor: Upload directory not set."));
}
}
示例4: index
public function index()
{
/*
|--------------------------------------------------------------------------
| Check for image
|--------------------------------------------------------------------------
|
| Transform just needs the path to an image to get started. If it exists,
| the fun begins.
|
*/
$image_src = $this->fetchParam('src', null, false, false, false);
// Set full system path
$image_path = Path::tidy(BASE_PATH . '/' . $image_src);
// Check if image exists before doing anything.
if (!File::isImage($image_path)) {
Log::error("Could not find requested image to transform: " . $image_path, "core", "Transform");
return;
}
/*
|--------------------------------------------------------------------------
| Resizing and cropping options
|--------------------------------------------------------------------------
|
| The first transformations we want to run is for size to reduce the
| memory usage for future effects.
|
*/
$width = $this->fetchParam('width', null, 'is_numeric');
$height = $this->fetchParam('height', null, 'is_numeric');
// resize specific
$ratio = $this->fetchParam('ratio', true, false, true);
$upsize = $this->fetchParam('upsize', true, false, true);
// crop specific
$pos_x = $this->fetchParam('pos_x', 0, 'is_numeric');
$pos_y = $this->fetchParam('pos_y', 0, 'is_numeric');
$quality = $this->fetchParam('quality', '75', 'is_numeric');
/*
|--------------------------------------------------------------------------
| Action
|--------------------------------------------------------------------------
|
| Available actions: resize, crop, and guess.
|
| "Guess" will find the best fitting aspect ratio of your given width and
| height on the current image automatically, cut it out and resize it to
| the given dimension.
|
*/
$action = $this->fetchParam('action', 'resize');
/*
|--------------------------------------------------------------------------
| Extra bits
|--------------------------------------------------------------------------
|
| Delicious and probably rarely used options.
|
*/
$angle = $this->fetchParam('rotate', false);
$flip_side = $this->fetchParam('flip', false);
$blur = $this->fetchParam('blur', false, 'is_numeric');
$pixelate = $this->fetchParam('pixelate', false, 'is_numeric');
$grayscale = $this->fetchParam('grayscale', false, false, true);
// Silly brits
$greyscale = $this->fetchParam('greyscale', $grayscale, false, true);
/*
|--------------------------------------------------------------------------
| Assemble filename and check for duplicate
|--------------------------------------------------------------------------
|
| We need to make sure we don't already have this image created, so we
| defer any action until we've processed the parameters, which create
| a unique filename.
|
*/
// Find .jpg, .png, etc
$extension = File::getExtension($image_path);
// Filename with the extension removed so we can append our unique filename flags
$stripped_image_path = str_replace('.' . $extension, '', $image_path);
// The possible filename flags
$parameter_flags = array('width' => $width, 'height' => $height, 'quality' => $quality, 'rotate' => $angle, 'flip' => $flip_side, 'pos_x' => $pos_x, 'pos_y' => $pos_y, 'blur' => $blur, 'pixelate' => $pixelate, 'greyscale' => $greyscale);
// Start with a 1 character action flag
$file_breadcrumbs = '-' . $action[0];
foreach ($parameter_flags as $param => $value) {
if ($value) {
$flag = is_bool($value) ? '' : $value;
// don't show boolean flags
$file_breadcrumbs .= '-' . $param[0] . $flag;
}
}
// Allow converting filetypes (jpg, png, gif)
$extension = $this->fetchParam('type', $extension);
// Allow saving in a different directory
$destination = $this->fetchParam('destination', Config::get('transform_destination', false), false, false, false);
if ($destination) {
$destination = Path::tidy(BASE_PATH . '/' . $destination);
// Method checks to see if folder exists before creating it
Folder::make($destination);
$stripped_image_path = Path::tidy($destination . '/' . basename($stripped_image_path));
}
//.........这里部分代码省略.........
示例5: upload
/**
* Upload a file.
*
* @param string $file Name of file
* @param string $target target of file
* @param string $filename Name of new file
* @return bool
**/
public static function upload($file, $destination, $add_root_variable = false, $renamed_file = false)
{
Folder::make($destination);
$info = pathinfo($file['name']);
$extension = $info['extension'];
$filename = $renamed_file ?: $info['filename'];
// build filename
$new_filename = Path::assemble(BASE_PATH, $destination, $filename . '.' . $extension);
// check for dupes
if (File::exists($new_filename)) {
$new_filename = Path::assemble(BASE_PATH, $destination, $filename . '-' . date('YmdHis') . '.' . $extension);
}
// Check if destination is writable
if (!Folder::isWritable($destination)) {
Log::error('Upload failed. Directory "' . $destination . '" is not writable.', 'core');
return null;
}
// write file
move_uploaded_file($file['tmp_name'], $new_filename);
return Path::toAsset($new_filename, $add_root_variable);
}
示例6: markAsSpam
public function markAsSpam($file)
{
$info = new SplFileInfo($file);
$filename = $info->getFilename();
$directory = str_replace($filename, '', $file) . 'spam/';
Folder::make($directory);
File::move($file, Path::assemble($directory, $filename));
}
示例7: uploadBatch
/**
* Upload file(s)
*
* @param string $destination Where the file is going
* @param string $id The field took look at in the files array
* @return array
*/
public static function uploadBatch($destination = null, $id = null)
{
$destination = $destination ?: Request::get('destination');
$id = $id ?: Request::get('id');
$files = self::standardizeFileUploads($_FILES);
$results = array();
// Resizing configuration
if ($resize = Request::get('resize')) {
$width = Request::get('width', null);
$height = Request::get('height', null);
$ratio = Request::get('ratio', true);
$upsize = Request::get('upsize', false);
$quality = Request::get('quality', '75');
}
// If $files[$id][0] exists, it means there's an array of images.
// If there's not, there's just one. We want to change this to an array.
if ( ! isset($files[$id][0])) {
$tmp = $files[$id];
unset($files[$id]);
$files[$id][] = $tmp;
}
// Process each image
foreach ($files[$id] as $file) {
// Image data
$path = File::upload($file, $destination);
$name = basename($path);
// Resize
if ($resize) {
$image = \Intervention\Image\Image::make(Path::assemble(BASE_PATH, $path));
$resize_folder = Path::assemble($image->dirname, 'resized');
if ( ! Folder::exists($resize_folder)) {
Folder::make($resize_folder);
}
$resize_path = Path::assemble($resize_folder, $image->basename);
$path = Path::toAsset($resize_path);
$name = basename($path);
$image->resize($width, $height, $ratio, $upsize)->save($resize_path, $quality);
}
$results[] = compact('path', 'name');
}
return $results;
}
示例8: save
/**
* Save submission to file
*
* @param array $data Array of values to store
* @param array $config Array of configuration values
* @param string $location Path to folder where submissions should be saved
* @param string $prefix Filename prefix to use for submission file
* @param string $suffix Filename suffix to use for submission file
* @return void
*/
private function save($data, $config, $location, $is_spam = false)
{
if (array_get($this->config, 'master_killswitch')) {
return;
}
$EXT = array_get($config, 'submission_save_extension', 'yaml');
// Clean up whitespace
array_walk_recursive($data, function (&$value, $key) {
$value = trim($value);
});
if (!File::exists($location)) {
Folder::make($location);
}
if ($format = array_get($config, 'filename_format')) {
$now = time();
$time_variables = array('year' => date('Y', $now), 'month' => date('m', $now), 'day' => date('d', $now), 'hour' => date('G', $now), 'minute' => date('i', $now), 'minutes' => date('i', $now), 'second' => date('s', $now), 'seconds' => date('s', $now));
$available_variables = $time_variables + $data;
$filename = Parse::template($format, $available_variables);
} else {
$filename = date('Y-m-d-Gi-s', time());
}
if ($is_spam) {
$location = $location . 'spam/';
Folder::make($location);
}
// Put it in the right folder
$filename = $location . $filename;
// Ensure a unique filename in the event two forms are submitted in the same second
if (File::exists($filename . '.' . $EXT)) {
for ($i = 1; $i < 60; $i++) {
if (!file_exists($filename . '-' . $i . '.' . $EXT)) {
$filename = $filename . '-' . $i;
break;
}
}
}
$filename .= '.' . $EXT;
if ($EXT === 'json') {
File::put($filename, json_encode($data));
} else {
File::put($filename, Yaml::dump($data) . '---');
}
}
示例9: elseif
if (isset($form_data['new'])) {
if ($form_data['type'] == 'date') {
$date_or_datetime = Config::getEntryTimestamps() ? $datestamp . "-" . $timestamp : $datestamp;
$file = $content_root . "/" . $path . "/" . $status_prefix . $date_or_datetime . "-" . $slug . "." . $content_type;
} elseif ($form_data['type'] == 'number') {
$slug = $numeric . "." . $slug;
$file = $content_root . "/" . $path . "/" . $status_prefix . $slug . "." . $content_type;
} elseif ($form_data['type'] == 'none') {
if (!preg_match(Pattern::NUMERIC, $slug, $matches)) {
$numeric = Statamic::get_next_numeric_folder($path);
$slug = $numeric . "-" . $slug;
}
$file = $content_root . "/" . $path . "/" . $status_prefix . $slug . "/page." . $content_type;
$file = Path::tidy($file);
if (!File::exists(dirname($file))) {
Folder::make(dirname($file));
}
} else {
$file = $content_root . "/" . $path . "/" . $form_data['original_slug'] . "." . $content_type;
}
$folder = $path;
} else {
$file = Path::assemble(Config::getContentRoot(), $path) . '.' . $content_type;
}
// load the original yaml
if (isset($form_data['new'])) {
$file_data = array();
} else {
$page = basename($path);
$folder = dirname($path);
$file_data = Statamic::get_content_meta($page, $folder, true);
示例10: index
//.........这里部分代码省略.........
| Available actions: resize, crop, and guess.
|
| "Guess" will find the best fitting aspect ratio of your given width and
| height on the current image automatically, cut it out and resize it to
| the given dimension.
|
*/
$action = $this->fetchParam('action', 'resize');
/*
|--------------------------------------------------------------------------
| Extra bits
|--------------------------------------------------------------------------
|
| Delicious and probably rarely used options.
|
*/
$angle = $this->fetchParam('rotate', false);
$flip_side = $this->fetchParam('flip' , false);
$blur = $this->fetchParam('blur', false, 'is_numeric');
$pixelate = $this->fetchParam('pixelate', false, 'is_numeric');
$greyscale = $this->fetchParam(array('greyscale', 'grayscale'), false, false, true);
$watermark = $this->fetchParam('watermark', false, false, false, false);
/*
|--------------------------------------------------------------------------
| Assemble filename and check for duplicate
|--------------------------------------------------------------------------
|
| We need to make sure we don't already have this image created, so we
| defer any action until we've processed the parameters, which create
| a unique filename.
|
*/
// Late modified time of original image
$last_modified = ($is_external) ? false : File::getLastModified($image_path);
// Find .jpg, .png, etc
$extension = File::getExtension($image_path);
// Filename with the extension removed so we can append our unique filename flags
$stripped_image_path = str_replace('.' . $extension, '', $image_path);
// The possible filename flags
$parameter_flags = array(
'width' => $width,
'height' => $height,
'quality' => $quality,
'rotate' => $angle,
'flip' => $flip_side,
'pos_x' => $pos_x,
'pos_y' => $pos_y,
'blur' => $blur,
'pixelate' => $pixelate,
'greyscale' => $greyscale,
'modified' => $last_modified
);
// Start with a 1 character action flag
$file_breadcrumbs = '-'.$action[0];
示例11: upload
/**
* Upload a file.
*
* @param string $file Name of file
* @param string $destination Destination of file
* @param string $filename Name of new file
* @return bool
**/
public static function upload($file, $destination, $filename = null)
{
Folder::make($destination);
return move_uploaded_file($file, $destination . '/' . $filename);
}