Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * testCopy method
  *
  * @return void
  */
 public function testCopy()
 {
     $dest = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tests/cakephp.file.test.tmp';
     $file = __FILE__;
     $this->file = new File($file);
     $result = $this->file->copy($dest);
     $this->assertTrue($result);
     $result = $this->file->copy($dest, true);
     $this->assertTrue($result);
     $result = $this->file->copy($dest, false);
     $this->assertFalse($result);
     $this->file->close();
     unlink($dest);
     $TmpFile = new File('/this/does/not/exist');
     $result = $TmpFile->copy($dest);
     $this->assertFalse($result);
     $TmpFile->close();
 }