當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。