本文整理汇总了PHP中Cake\Filesystem\File::create方法的典型用法代码示例。如果您正苦于以下问题:PHP File::create方法的具体用法?PHP File::create怎么用?PHP File::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeAndCreateFolder
private function removeAndCreateFolder($path)
{
$dir = new Folder($path);
$dir->delete();
$dir->create($path);
$file = new File($path . DS . 'empty');
$file->create();
}
示例2: upload
public function upload($path = null)
{
$root = WWW_ROOT;
$fullPath = $root . $path;
if ($this->request->is('post')) {
foreach ($this->request->data['file'] as $file) {
$new = new File($fullPath . DS . $file['name'], false);
if (!$new->exists()) {
$new->create();
$new->write(file_get_contents($file['tmp_name']));
}
}
if (count($this->request->data['file']) > 1) {
$this->Flash->success(__('The files have been saved.'));
} else {
$this->Flash->success(__('The file has been saved.'));
}
return $this->redirect(['action' => 'index', $path]);
}
$this->Flash->error(__('The file(s) could not be saved.'));
}
示例3: _getFromUrl
/**
* Prepares install from remote URL.
*
* @return bool True on success
*/
protected function _getFromUrl()
{
try {
$http = new Client(['redirect' => 3]);
// follow up to 3 redirections
$response = $http->get($this->params['source'], [], ['headers' => ['X-Requested-With' => 'XMLHttpRequest']]);
} catch (\Exception $ex) {
$response = false;
$this->err(__d('installer', 'Could not download the package. Details: {0}', $ex->getMessage()));
return false;
}
if ($response && $response->isOk()) {
$this->params['source'] = TMP . substr(md5($this->params['source']), 24) . '.zip';
$file = new File($this->params['source']);
$responseBody = $response->body();
if (is_readable($file->pwd())) {
$file->delete();
}
if (!empty($responseBody) && $file->create() && $file->write($responseBody, 'w+', true)) {
$file->close();
return $this->_getFromFile();
$this->err(__d('installer', 'Unable to extract the package.'));
return false;
}
$this->err(__d('installer', 'Unable to download the file, check write permission on "{0}" directory.', [TMP]));
return false;
}
$this->err(__d('installer', 'Could not download the package, no .ZIP file was found at the given URL.'));
return false;
}
示例4: runjobs
/**
* Process the tasks when they need to run
*
* @access private
* @return void
*/
private function runjobs()
{
$dir = new Folder(TMP);
// set processing flag so function takes place only once at any given time
$processing = count($dir->find('\\.scheduler_running_flag'));
$processingFlag = new File($dir->slashTerm($dir->pwd()) . '.scheduler_running_flag');
if ($processing && time() - $processingFlag->lastChange() < $this->processingTimeout) {
$this->out("Scheduler already running! Exiting.");
return false;
} else {
$processingFlag->delete();
$processingFlag->create();
}
if (!$this->storePath) {
$this->storePath = TMP;
}
// look for a store of the previous run
$store = "";
$storeFilePath = $this->storePath . $this->storeFile;
if (file_exists($storeFilePath)) {
$store = file_get_contents($storeFilePath);
}
$this->out('Reading from: ' . $storeFilePath);
// build or rebuild the store
if ($store != '') {
$store = json_decode($store, true);
} else {
$store = $this->schedule;
}
// run the jobs that need to be run, record the time
foreach ($this->schedule as $name => $job) {
$now = new DateTime();
$task = $job['task'];
$action = $job['action'];
// if the job has never been run before, create it
if (!isset($store[$name])) {
$store[$name] = $job;
}
// figure out the last run date
$tmptime = $store[$name]['lastRun'];
if ($tmptime == null) {
$tmptime = new DateTime("1969-01-01 00:00:00");
} elseif (is_array($tmptime)) {
$tmptime = new DateTime($tmptime['date'], new DateTimeZone($tmptime['timezone']));
} elseif (is_string($tmptime)) {
$tmptime = new DateTime($tmptime);
}
// determine the next run time based on the last
if (substr($job['interval'], 0, 1) === 'P') {
$tmptime->add(new DateInterval($job['interval']));
// "P10DT4H" http://www.php.net/manual/en/class.dateinterval.php
} else {
$tmptime->modify($job['interval']);
// "next day 10:30" http://www.php.net/manual/en/datetime.formats.relative.php
}
// is it time to run? has it never been run before?
if ($tmptime <= $now) {
$this->hr();
$this->out("Running {$name}");
$this->hr();
if (!isset($this->{$task})) {
$this->{$task} = $this->Tasks->load($task);
// load models if they aren't already
// foreach ($this->$task->uses as $mk => $mv) {
// if (!isset($this->$task->$mv)) {
// App::uses('AppModel', 'Model');
// App::uses($mv, 'Model');
// $this->$task->$mv = new $mv();
// }
// }
}
// grab the entire schedule record incase it was updated..
$store[$name] = $this->schedule[$name];
// execute the task and store the result
$store[$name]['lastResult'] = call_user_func_array(array($this->{$task}, $action), $job['args']);
// assign it the current time
$now = new DateTime();
$store[$name]['lastRun'] = $now->format('Y-m-d H:i:s');
}
}
// write the store back to the file
file_put_contents($this->storePath . $this->storeFile, json_encode($store));
// remove processing flag
$processingFlag->delete();
}
示例5: testDirSize
/**
* testDirSize method
*
* @return void
*/
public function testDirSize()
{
$path = TMP . 'tests' . DS;
$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());
}
示例6: makeTmp
/**
* Make copy of the original file as a temporary file or working
* file. This is used to prevent uncommitted changes affecting
* the original file.
*
* @return boolean Success
*/
public function makeTmp()
{
// Create tmp folder if not found
$tmpDir = new Folder($this->tmpDirFull, true, 0755);
$tmpPath = $this->tmpDirPath . DS . $this->source() . '-' . $this->_properties['id'];
$tmpPathFull = WWW_ROOT . $tmpPath;
$tmpFile = new File($tmpPathFull);
$tmpFile->create();
$original = new File($this->_getOriginalPath());
if ($original->copy($tmpPathFull)) {
$this->tmpPath = $tmpPath;
$this->tmpPathFull = $tmpPathFull;
return true;
}
}
示例7: testSortByName
/**
* Verify that the order using name is correct.
*/
public function testSortByName()
{
$Folder = new Folder(TMP . 'tests', true);
$fileA = new File($Folder->pwd() . DS . 'a.txt');
$fileA->create();
$fileC = new File($Folder->pwd() . DS . 'c.txt');
$fileC->create();
sleep(1);
$fileB = new File($Folder->pwd() . DS . 'b.txt');
$fileB->create();
$results = $Folder->find('.*', Folder::SORT_NAME);
$this->assertSame(['a.txt', 'b.txt', 'c.txt'], $results);
}