选择语言 :

 Core_File::create_file

创建一个文件,多服务器可以自动同步

boolean Core_File::create_file( string $file , $data $data [, $flags $flags = null , $context $context = null , string $storage = string(7) "default" ] )

参数列表

参数 类型 描述 默认值
$file string $file
$data $data
$flags $flags null
$context $context null
$storage string 物理存储组,不传则为默认 string(7) "default"
返回值
  • boolean
File: ./core/classes/file.class.php
public static function create_file($file, $data ,$flags = null, $context = null, $storage = 'default')
{
    $info = File::check_and_get_path($file);

    # 系统禁用了写入功能
    if (Core::is_file_write_disabled())return false;

    if (File::can_do_run($storage))
    {
        # 系统内部运行时或小于等于1台服时执行

        $dir = substr($file, 0, (int)strrpos(str_replace('\\', '/', $file), '/'));

        if ($dir && !is_dir($dir))
        {
            # 没有文件夹先则创建
            File::create_dir($dir);
        }

        if (false!==@file_put_contents($file, $data , $flags , $context))
        {
            @chmod($file, 0666);

            return true;
        }
        else
        {
            if (IS_DEBUG)Core::debug()->error('create file error:'.Core::debug_path($file));
            return false;
        }
    }
    else
    {
        return File::call_http_host($storage, 'file/create_file', $info[0], $info[1], $data, $flags, $context);
    }
}