当前位置: 首页>>代码示例>>PHP>>正文


PHP LocalFile::createNewFile方法代码示例

本文整理汇总了PHP中LocalFile::createNewFile方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::createNewFile方法的具体用法?PHP LocalFile::createNewFile怎么用?PHP LocalFile::createNewFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LocalFile的用法示例。


在下文中一共展示了LocalFile::createNewFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCreateNewFile

 public function testCreateNewFile()
 {
     //non-existing file
     $myFile2 = new LocalFile(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext');
     $this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     $this->assertTrue($myFile2->createNewFile());
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     //already existing file (overwrite = false)
     try {
         $myFile2->createNewFile();
         $this->fail();
     } catch (EyeIOException $e) {
         //normal situation
     }
     //already existing file (overwrite = true)
     $content = '## My Content ##';
     file_put_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext', $content);
     $this->assertEquals($content, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     try {
         $myFile2->createNewFile(true);
     } catch (EyeIOException $e) {
         $this->fail();
     }
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     $this->assertEquals('', file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext');
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:27,代码来源:LocalFileTest.php

示例2: createNewFile

 /**
  * @param bool $overwrite Set to TRUE to try overwriting the file if it already exists
  * @return void
  * @throws EyeIOException
  */
 public function createNewFile($overwrite = false)
 {
     $this->getParentFile()->checkWritePermission();
     try {
         return parent::createNewFile($overwrite);
     } catch (EyeIOException $e) {
         throw new EyeIOException('Unable to create file at ' . $this->getAbsolutePath());
     }
 }
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:14,代码来源:LocalFile.php


注:本文中的LocalFile::createNewFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。