/** * Save an uploaded file to a new location. If no filename is provided, * the original filename will be used, with a unique prefix added. * * This method should be used after validating the $_FILES array: * * if ($array->check()) * { * // Upload is valid, save it * Upload::save($array['file']); * } * * @param array $file uploaded file data * @param string $filename new filename * @param string $directory new directory * @param integer $chmod chmod mask * @return string on success, full path to new file * @return FALSE on failure */ public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644) { if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) { // Ignore corrupted uploads return FALSE; } if ($filename === NULL) { // Use the default filename, with a timestamp pre-pended $filename = uniqid() . $file['name']; } // Remove spaces from the filename $filename = preg_replace('/\\s+/u', '_', $filename); if ($directory === NULL) { // Use the pre-configured upload directory $directory = Upload::$default_directory; } if (!is_dir($directory) or !is_writable(realpath($directory))) { throw new Exception('Directory :dir must be writable', [':dir' => Debug::path($directory)]); } // Make the filename into a complete path $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($file['tmp_name'], $filename)) { if ($chmod !== FALSE) { // Set permissions on filename chmod($filename, $chmod); } // Return new file path return $filename; } return FALSE; }
/** * Get a single line of text representing the exception: * * Error [ Code ]: Message ~ File [ Line ] * * @param \Throwable $e * @return string */ public static function text(\Throwable $e) { return sprintf('%s [ %s ]: %s ~ %s [ %d ]', get_class($e), $e->getCode(), strip_tags($e->getMessage()), \mii\util\Debug::path($e->getFile()), $e->getLine()); }
/** * Dump and die */ function dd(...$params) { if (Mii::$app instanceof \mii\web\App) { echo "<style>pre { padding: 5px; background-color: #f9feff; font-size: 14px; font-family: monospace; text-align: left; color: #111;overflow: auto; white-space: pre-wrap; }"; echo "pre small { font-size: 1em; color: #000080;font-weight:bold}"; echo "</style><pre>\n"; array_map(function ($a) { echo \mii\util\Debug::dump($a); }, $params); echo "</pre>\n"; } else { array_map(function ($a) { var_dump($a); }, $params); } die; }
?> </a></h3> <div id="<?php echo $env_id; ?> " class="collapsed"> <table cellspacing="0"> <?php foreach ($GLOBALS[$var] as $key => $value) { ?> <tr> <td><code><?php echo \mii\util\HTML::chars($key); ?> </code></td> <td><pre><?php echo \mii\util\Debug::dump($value); ?> </pre></td> </tr> <?php } ?> </table> </div> <?php } ?> </div> </div>
/** * Save the image. If the filename is omitted, the original image will * be overwritten. * * // Save the image as a PNG * $image->save('saved/cool.png'); * * // Overwrite the original image * $image->save(); * * [!!] If the file exists, but is not writable, an exception will be thrown. * * [!!] If the file does not exist, and the directory is not writable, an * exception will be thrown. * * @param string $file new image path * @param integer $quality quality of image: 1-100 * @return boolean * @uses Image::_save * @throws Kohana_Exception */ public function save($file = NULL, $quality = 100) { if ($file === NULL) { // Overwrite the file $file = $this->file; } if (is_file($file)) { if (!is_writable($file)) { throw new ImageException('File must be writable: :file', [':file' => Debug::path($file)]); } } else { // Get the directory of the file $directory = realpath(pathinfo($file, PATHINFO_DIRNAME)); if (!is_dir($directory) or !is_writable($directory)) { throw new ImageException('Directory must be writable: :directory', [':directory' => Debug::path($directory)]); } } // The quality must be in the range of 1 to 100 $quality = min(max($quality, 1), 100); return $this->_do_save($file, $quality); }
/** * Renders the view object to a string. Global and local data are merged * and extracted to create local variables within the view file. * * $output = $view->render(); * * [!!] Global variables with the same key name as local variables will be * overwritten by the local variable. * * @param string $file view filename * @return string * @uses Block::capture */ public function render($force = false) { if (!$this->_loaded and !$force) { return ''; } if (empty($this->_file)) { throw new Exception('Block :block does not have a php file', [':block' => $this->__name]); } $benchmark = false; if (config('debug')) { $benchmark = \mii\util\Profiler::start('Block:render', \mii\util\Debug::path($this->_file)); } // Combine local and global data and capture the output $c = $this->capture($this->_file); if ($benchmark) { \mii\util\Profiler::stop($benchmark); } return $c; }