Beispiel #1
0
 /**
  * Reads out a file, and echos the content to the client.
  *
  * @param File $file File object
  * @param array $range The range to read out of the file.
  * @return bool True is whole file is echoed successfully or false if client connection is lost in between
  */
 protected function _sendFile($file, $range)
 {
     $compress = $this->outputCompressed();
     $file->open('rb');
     $end = $start = false;
     if ($range) {
         list($start, $end) = $range;
     }
     if ($start !== false) {
         $file->offset($start);
     }
     $bufferSize = 8192;
     set_time_limit(0);
     session_write_close();
     while (!feof($file->handle)) {
         if (!$this->_isActive()) {
             $file->close();
             return false;
         }
         $offset = $file->offset();
         if ($end && $offset >= $end) {
             break;
         }
         if ($end && $offset + $bufferSize >= $end) {
             $bufferSize = $end - $offset + 1;
         }
         echo fread($file->handle, $bufferSize);
         if (!$compress) {
             $this->_flushBuffer();
         }
     }
     $file->close();
     return true;
 }
Beispiel #2
0
 /**
  * testCopy method
  *
  * @return void
  */
 public function testCopy()
 {
     $dest = TMP . '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();
 }
 /**
  * Write the files that need to be stored
  *
  * @return void
  */
 protected function _writeFiles()
 {
     $overwriteAll = false;
     if (!empty($this->params['overwrite'])) {
         $overwriteAll = true;
     }
     foreach ($this->_storage as $category => $domains) {
         foreach ($domains as $domain => $sentences) {
             $output = $this->_writeHeader();
             foreach ($sentences as $sentence => $header) {
                 $output .= $header . $sentence;
             }
             $filename = $domain . '.pot';
             if ($category === 'LC_MESSAGES') {
                 $File = new File($this->_output . $filename);
             } else {
                 new Folder($this->_output . $category, true);
                 $File = new File($this->_output . $category . DS . $filename);
             }
             $response = '';
             while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
                 $this->out();
                 $response = $this->in(__d('cake_console', 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename), ['y', 'n', 'a'], 'y');
                 if (strtoupper($response) === 'N') {
                     $response = '';
                     while (!$response) {
                         $response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
                         $File = new File($this->_output . $response);
                         $filename = $response;
                     }
                 } elseif (strtoupper($response) === 'A') {
                     $overwriteAll = true;
                 }
             }
             $File->write($output);
             $File->close();
         }
     }
 }
Beispiel #4
0
 /**
  * testDirSize method
  *
  * @return void
  */
 public function testDirSize()
 {
     $path = TMP . 'tests/';
     $Folder = new Folder($path . 'config_non_existent', true);
     $this->assertEquals(0, $Folder->dirSize());
     $File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
     $File->create();
     $File->write('something here');
     $File->close();
     $this->assertEquals(14, $Folder->dirSize());
 }