/** * Reads out a file, and echos the content to the client. * * @param File $file File object * @return bool True is whole file is echoed successfully or false if client connection is lost in between */ protected function _sendFile($file) { $compress = $this->outputCompressed(); $file->open('rb'); $bufferSize = 8192; set_time_limit(0); session_write_close(); while (!feof($file->fileHandle())) { if (connection_status() !== CONNECTION_NORMAL or connection_aborted()) { $file->close(); return false; } echo fread($file->fileHandle(), $bufferSize); if (!$compress) { flush(); if (ob_get_level()) { ob_flush(); } } } $file->close(); return true; }
/** * testWritable method * * @return void */ public function testWritable() { $someFile = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'some_file.txt', false); $this->assertTrue($someFile->open()); $this->assertTrue($someFile->writable()); $someFile->close(); $someFile->delete(); }