當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::open方法代碼示例

本文整理匯總了PHP中Cake\Filesystem\File::open方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::open方法的具體用法?PHP File::open怎麽用?PHP File::open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Filesystem\File的用法示例。


在下文中一共展示了File::open方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testLastChange

 /**
  * testLastChange method
  *
  * @return void
  */
 public function testLastChange()
 {
     $someFile = new File(TMP . 'some_file.txt', false);
     $this->assertFalse($someFile->lastChange());
     $this->assertTrue($someFile->open('r+'));
     $this->assertWithinRange(time(), $someFile->lastChange(), 2);
     $someFile->write('something');
     $this->assertWithinRange(time(), $someFile->lastChange(), 2);
     $someFile->close();
     $someFile->delete();
 }
開發者ID:Slayug,項目名稱:castor,代碼行數:16,代碼來源:FileTest.php

示例2: _sendFile

 /**
  * 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;
 }
開發者ID:rabinpal,項目名稱:cakephp,代碼行數:41,代碼來源:Response.php

示例3: export


//.........這裏部分代碼省略.........
         } elseif ($table == 5) {
             $tableName = 'seats';
             $seatsTable = TableRegistry::get('seats');
             $query = $seatsTable->find('all');
             $str = "id" . "," . "theater" . "," . "section" . "," . "row" . "," . "code" . "," . "price\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= $item->theater_id . ",";
                 $str .= $item->section_id . ",";
                 $str .= $item->row_id . ",";
                 $str .= "\"" . $item->code . "\"" . ",";
                 $str .= $item->price;
                 $str .= "\r\n";
             }
         } elseif ($table == 6) {
             $tableName = 'seasons';
             $seasonsTable = TableRegistry::get('seasons');
             $query = $seasonsTable->find('all');
             $str = "id" . "," . "name" . "," . "start_time" . "," . "end_time" . "," . "ticket_price" . "," . "theater_id" . "\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= "\"" . $item->name . "\"" . ",";
                 $str .= $item->start_time . ",";
                 $str .= $item->end_time . ",";
                 $str .= $item->ticket_price . ",";
                 $str .= $item->theater_id . ",";
                 $str .= "\"" . $item->about . "\"";
                 $str .= "\r\n";
             }
         } elseif ($table == 7) {
             $tableName = 'rows';
             $rowsTable = TableRegistry::get('rows');
             $query = $rowsTable->find('all');
             $str = "id" . "," . "theater" . "," . "section" . "," . "code\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= $item->theater_id . ",";
                 $str .= $item->section_id . ",";
                 $str .= "\"" . $item->code . "\"";
                 $str .= "\r\n";
             }
         } elseif ($table == 8) {
             $tableName = 'plays';
             $playsTable = TableRegistry::get('plays');
             $query = $playsTable->find('all');
             $str = "id" . "," . "name" . "," . "artwork" . "," . "description" . "," . "author\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= "\"" . $item->name . "\"" . ",";
                 $str .= "\"" . $item->artwork . "\"" . ",";
                 $str .= "\"" . $item->description . "\"" . ",";
                 $str .= "\"" . $item->author . "\"" . ",";
                 $str .= "\"" . $item->shortname . "\"";
                 $str .= "\r\n";
             }
         } elseif ($table == 9) {
             $tableName = 'performances';
             $ticketsTable = TableRegistry::get('performances');
             $query = $ticketsTable->find('all');
             $str = "id" . "," . "start_time" . "," . "open" . "," . "canceled" . "," . "play_id" . "," . "theater_id" . "," . "season_id\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= $item->start_time . ",";
                 $str .= $item->open . ",";
                 $str .= $item->canceled . ",";
                 $str .= $item->play_id . ",";
                 $str .= $item->theater_id . ",";
                 $str .= $item->season_id;
                 $str .= "\r\n";
             }
         } elseif ($table == 10) {
             $tableName = 'cart_items';
             $ticketsTable = TableRegistry::get('cart_items');
             $query = $ticketsTable->find('all');
             $str = "id" . "," . "cart_id" . "," . "performance_id" . "," . "seat_id" . "," . "season_ticket\r\n";
             $results = $query->toArray();
             foreach ($results as $item) {
                 $str .= $item->id . ",";
                 $str .= "\"" . $item->cart_id . "\"" . ",";
                 $str .= "\"" . $item->performance_id . "\"" . ",";
                 $str .= $item->seat_id . ",";
                 $str .= $item->season_id;
                 $str .= "\r\n";
             }
         } else {
             $this->Flash->error('Unexpected table value');
         }
         $file = new File('tmp/', true);
         $file->open('w');
         $file->append($str);
         $this->response->file($file->path, ['download' => true, 'name' => $tableName . '.csv']);
     } else {
         $this->set('file_status', 'Please submit a file.');
     }
 }
開發者ID:JesseDarellMoore,項目名稱:CS499,代碼行數:101,代碼來源:SetupAdminController.php


注:本文中的Cake\Filesystem\File::open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。