public static function getMime(Charcoal_File $image_file) { if (!$image_file->exists()) { return NULL; } $data = getimagesize(us($image_file->getPath())); if ($data === FALSE) { _throw(new Charcoal_ImageGetSizeException($image_file)); } return $data['mime']; }
public function __construct($path, $parent = NULL) { Charcoal_ParamTrait::validateString(1, $path); Charcoal_ParamTrait::validateIsA(2, 'Charcoal_File', $parent, TRUE); parent::__construct($path, $parent); if (!is_readable(parent::getPath())) { _throw(new Charcoal_FileNotFoundException($this)); } $this->_data = getimagesize(parent::getPath()); if ($this->_data === FALSE) { _throw(new Charcoal_ImageGetSizeException($this)); } }
/** * Output file * * @param Charcoal_File $file path to output * @param array $lines each line of the file to output */ public static function outputFile(Charcoal_File $file, array $lines) { $file_name = $file->getPath(); $fp = fopen($file_name, "w"); if ($fp === FALSE) { _throw(new Charcoal_FileOpenException($file)); } foreach ($lines as $line) { $res = fwrite($fp, $line . PHP_EOL); if ($res === FALSE) { _throw(new Charcoal_FileOutputException($file)); } } fclose($fp); }
/** * Rename the file or directory * * @param Charcoal_File $new_file */ public function rename($new_file) { $res = rename($this->path, $new_file->getPath()); if ($res === FALSE) { _throw(new Charcoal_FileRenameException($this->getPath(), $new_file->getPath())); } }