Create an empty file.

@param string $pPath Absolute path to the file to create
@param string $pContent Optional file content
@return bool
351989
public static function create($pPath, $pContent = '')
    {
        if (! file_exists($pPath)) {
            if (! $fp = fopen($pPath, 'w') or ! chmod($pPath, 0777)) {
                return false;
            }

            if ($pContent) {
                fwrite($fp, $pContent);
            }

            fclose($fp);

            return true;
        }

        return false;
    }
797870
public static function createFromPath($path)
    {
        if (!file_exists($path)) {
            throw new Exception\FactoryException(sprintf('Unable to open file %s', $path));
        }
        $file = new \SplFileInfo($path);
        return static::createFromSplFileInfo($file);
    }
200025
public function createFile(string $path): File {
    $localFile = $this->instantiateFile($path);
    $localFile->create();
    return $localFile;
  }
421736
public static function put(string $filepath, string $content):int
    {
        if (!file_exists($filepath)) {
            Server::create($filepath, "file");
        }
        file_put_contents($filepath, $content);
        self::open($filepath);
        return (1);
    }
228703
public function create($path, $contents='')
    {
        $this->fs[$path] = $this->newFile();
        $this->fs[$path]->setPath($path);
        return $this->fs[$path];
    }
407522
public function fileXmlShouldBeLike($path, PyStringNode $text)
    {
        $path = $this->workingDir . '/' . $path;
        Assert::assertFileExists($path);

        $fileContent = trim(file_get_contents($path));

        $fileContent = preg_replace('/time="(.*)"/', 'time="-IGNORE-VALUE-"', $fileContent);

        $dom = new DOMDocument();
        $dom->loadXML($text);
        $dom->formatOutput = true;

        Assert::assertEquals(trim($dom->saveXML(null, LIBXML_NOEMPTYTAG)), $fileContent);
    }
1009324
public function generateFile($filename, $templateData, $templatePath = null)
    {
        $this->makeDirectory($this->rootPath);

        $path = $this->rootPath.$filename;

        if (is_null($templatePath)) {
            $templatePath = $this->templatePath;
        }
        
        $content = $this->generateContent($templatePath, $templateData);

        if (! file_exists($path)) {
            $this->fileHelper->put($path, $content);
            $this->command->info($filename.' created successfully.');
        } else {
            $this->command->info($filename.' already exists ... skipping.');
        }
    }
874326
public function create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid = null) {
        global $DB;

        // validate all parameters, we do not want any rubbish stored in database, right?
        if (!is_number($contextid) or $contextid < 1) {
            throw new file_exception('storedfileproblem', 'Invalid contextid');
        }

        $component = clean_param($component, PARAM_COMPONENT);
        if (empty($component)) {
            throw new file_exception('storedfileproblem', 'Invalid component');
        }

        $filearea = clean_param($filearea, PARAM_AREA);
        if (empty($filearea)) {
            throw new file_exception('storedfileproblem', 'Invalid filearea');
        }

        if (!is_number($itemid) or $itemid < 0) {
            throw new file_exception('storedfileproblem', 'Invalid itemid');
        }

        $filepath = clean_param($filepath, PARAM_PATH);
        if (strpos($filepath, '/') !== 0 or strrpos($filepath, '/') !== strlen($filepath)-1) {
            // path must start and end with '/'
            throw new file_exception('storedfileproblem', 'Invalid file path');
        }

        $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, '.');

        if ($dir_info = $this->get_file_by_hash($pathnamehash)) {
            return $dir_info;
        }

        static $contenthash = null;
        if (!$contenthash) {
            $this->add_string_to_pool('');
            $contenthash = self::hash_from_string('');
        }

        $now = time();

        $dir_record = new stdClass();
        $dir_record->contextid = $contextid;
        $dir_record->component = $component;
        $dir_record->filearea  = $filearea;
        $dir_record->itemid    = $itemid;
        $dir_record->filepath  = $filepath;
        $dir_record->filename  = '.';
        $dir_record->contenthash  = $contenthash;
        $dir_record->filesize  = 0;

        $dir_record->timecreated  = $now;
        $dir_record->timemodified = $now;
        $dir_record->mimetype     = null;
        $dir_record->userid       = $userid;

        $dir_record->pathnamehash = $pathnamehash;

        $DB->insert_record('files', $dir_record);
        $dir_info = $this->get_file_by_hash($pathnamehash);

        if ($filepath !== '/') {
            //recurse to parent dirs
            $filepath = trim($filepath, '/');
            $filepath = explode('/', $filepath);
            array_pop($filepath);
            $filepath = implode('/', $filepath);
            $filepath = ($filepath === '') ? '/' : "/$filepath/";
            $this->create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid);
        }

        return $dir_info;
    }
810925
private function createFile($path, $contents = '', $mode = 0666)
    {
        if (false === file_put_contents($path, $contents)) {
            throw new RuntimeException(
                sprintf(
                    'The file "%s" could not be written.',
                    $path
                )
            );
        }

        if (!chmod($path, $mode)) {
            throw new RuntimeException(
                sprintf(
                    'The file "%s" could not be chmodded to %o.',
                    $path,
                    $mode
                )
            );
        }
    }
397309
public static File createPathAndGetFile(File root, String relativePathToCreate) {
		File target = new File(root, relativePathToCreate);

		if (!target.exists()) {
			if (target.mkdirs()){
				return target;
			} else {
				log.warn("No se ha podido crear el directorio:'"+target.getAbsolutePath()+"'");
				return null;
			}
		} else {
			return target;
		}
	}
472544
public function createFileOnDFS( $filePath, $contents )
    {
        $this->accumulatorStart();

        $filePath = $this->makeDFSPath( $filePath );
        $ret = $this->createFile( $filePath, $contents, false );

        $this->accumulatorStop();

        return $ret;
    }
1065685
public static File createTmpPhpFileFromResource(String resourceName, boolean deleteOnExit) throws IOException {
		InputStream is = getInstance().getClass().getResourceAsStream(resourceName);
		if (is == null) {
			throw new IOException("Unable to find php file " + resourceName);
		}
		return copyFile(is, deleteOnExit);
	}
1295690
public function saveFile($filePath, $fileContent)
    {
        if (false === is_dir(dirname($filePath))) {
            mkdir(dirname($filePath), 0755);
        }

        return file_put_contents($filePath, $fileContent);
    }
400663
public function createFile($filepath, $script, $rewrite = true)
    {
        $this->createDirectory(dirname($filepath));
        
        if (!file_exists($filepath) || $rewrite === true) {
            file_put_contents($filepath, $script);
        }
        
        return $this;
    }
263043
private static function createAndWriteFile(string $path, string $contents)
    {
        $fileHandle = fopen($path, 'wb');
        if ($fileHandle === false) {
            throw new \RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
        }

        fwrite($fileHandle, $contents);
        fclose($fileHandle);
    }
458444
public function createPath()
    {
        if ($this->isReference()) {
            throw $this->noChildrenAllowed();
        }
        $p = new Path($this->project);
        $this->elements[] = $p;
        $this->checked = false;

        return $p;
    }
980373
public function create($path, array $data)
    {
        $data = array_merge($data, ['path' => $path]);

        return File::create($data);
    }