/** * @param Oops_File|string $file * @param string $name */ public function sendFile($file, $name = null) { if (!file_exists($file)) { $this->setCode(404); } if (!is_readable($file)) { $this->setCode(403); } if (!strlen($name)) { $name = $file; } // @todo try to use webserver for serving file $this->setHeader('Content-type', Oops_File_Utils::getMimeType($name)); switch (true) { case strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false: $name = mb_convert_encoding($name, 'windows-1251', 'utf-8'); case strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'opera') !== false: break; default: $name = '=?utf-8?B?' . base64_encode($name) . '?='; } $contentDisposition = 'attachment; filename="' . $name . '"'; $this->setHeader('Content-Disposition', $contentDisposition); clearstatcache(); $this->setHeader('Content-length', filesize($file)); $this->getReady(); $this->_sendHeaders(); readfile($file); die; }
public function __destruct() { if ($this->_isTemp && file_exists($this->_filename)) { if (is_file($this->_filename)) { unlink($this->_filename); } elseif (is_dir($this->_filename)) { Oops_File_Utils::removeDirRecursive($this->_filename); } } }
/** * Reads ini setting open_basedir and stores open real paths in class static * array * * @return unknown_type */ public static function initOpenBasedir() { if (!isset(self::$openBasedir)) { self::$openBasedir = array(); $dirs = explode(PATH_SEPARATOR, ini_get('open_basedir')); foreach ($dirs as $dir) { self::$openBasedir[] = realpath($dir); } } }
function test_FileUtils_SplitPath() { $string = 'abcdef0123456789a0b1c2d3e4f56789'; $result = Oops_File_Utils::splitPath('PreFix', $string, 4); $expected = 'PreFix' . DS . 'abcd' . DS . 'ef01' . DS . '2345' . DS . '6789' . DS . 'a0b1' . DS . 'c2d3' . DS . 'e4f5' . DS . '6789'; $this->assertEquals($expected, $result, "Split string to chunks with prefix"); $result = Oops_File_Utils::splitPath('PreFix', $string, 4, 6); $expected = 'PreFix' . DS . 'abcdef' . DS . '0123' . DS . '4567' . DS . '89a0' . DS . 'b1c2' . DS . 'd3e4' . DS . 'f567' . DS . '89'; $this->assertEquals($expected, $result, "Split string to chunks with prefix and skipping some leading chars"); $result = Oops_File_Utils::splitPath('', $string, 17); $expected = 'abcdef0123456789a' . DS . '0b1c2d3e4f56789'; $this->assertEquals($expected, $result, "Split string without prefix"); }
/** * Make a file (or directory) writable * @return bool True on success */ public function makeWriteable() { //if($this->isWritable()) return true; if (!$this->_exists) { $dir = new Oops_File($this->_dirname); if (!$dir->exists) { require_once "Oops/File/Utils.php"; try { Oops_File_Utils::autoCreateDir($dir->filename, 0777); } catch (Exception $e) { return false; } return true; } else { return $dir->makeWriteable(); } } else { if (is_writeable($this->_filename)) { return true; } if (is_file($this->_filename)) { return @chmod($this->_filename, 0666); } elseif (is_dir($this->_filename)) { return @chmod($this->_filename, 0777); } else { return false; } } }