/** * Set path to file for download * * The Last-Modified header will be set to files filemtime(), actually. * Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_FILE) if file doesn't exist. * Sends HTTP 404 status if $send_404 is set to true. * * @access public * @return mixed Returns true on success or PEAR_Error on failure. * @param string $file path to file for download * @param bool $send_404 whether to send HTTP/404 if * the file wasn't found */ function setFile($file, $send_404 = true) { $file = realpath($file); if (!Codendi_File::isFile($file)) { if ($send_404) { $this->HTTP->sendStatusCode(404); } return PEAR::raiseError("File '{$file}' not found.", HTTP_DOWNLOAD_E_INVALID_FILE); } $this->setLastModified(filemtime($file)); $this->file = PHP_BigFile::stream($file); $this->size = Codendi_File::getSize($file); return true; }
function testWithBigFile() { //$this->assertTrue(is_writeable($this->writePath), "$this->writePath should be writable"); $writeFile = fopen(PHP_BigFile::stream($this->writePath), 'wb'); $this->assertTrue($writeFile); $file = new FRSFile(); $file->file_location = $this->readPath; $fileSize = PHP_BigFile::getSize($this->readPath); $chunkSize = 8 * 1024 * 1024; $nbChunks = ceil($fileSize / $chunkSize); for ($i = 0; $i < $nbChunks; $i++) { $data = $file->getContent($i * $chunkSize, $chunkSize); $written = fwrite($writeFile, $data); $this->assertEqual(strlen($data), $written); } $this->assertIdentical(md5_file($this->readPath), md5_file($this->writePath)); }
/** * Returns the content of the file, in a raw resource * * +2GB safe * * @return mixed the content of the file */ function getContent($offset = 0, $size = -1) { if ($size == -1) { $size = $this->getFileSize(); } $path = PHP_BigFile::stream(realpath($this->getFileLocation())); return file_get_contents($path, false, NULL, $offset, $size); }