本文整理汇总了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();
}
示例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;
}
示例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.');
}
}