How to create a file directory in php? (Pure code)

不言
Release: 2023-04-03 15:26:01
Original
11015 people have browsed it

The content of this article is about how to create a file directory in PHP? (Pure code), it has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

//创建目录
/*
   *  @param  createfile //创建文件夹
   *  @param  createpath  // 创建的路径
   *  @param  file_exists() // 查看是否文件夹有同样的目录
   *  @param  file // 创建的的路径 基于文件夹 ./Public/Uploads/  下创建修改
   *  @param  mkdir // 创建文件夹的函数
   *  @param 2017/11/20  8:57
   */
 function createfile($file){

    $createpath = './Public/Uploads/' . $file;
    $_createpath = iconv('utf-8', 'gb2312', $createpath);
    if (file_exists($_createpath) == false)
    {
        //检查是否有该文件夹,如果没有就创建,并给予最高权限
        if (mkdir($_createpath, 0700, true)) {
            $value['file'] ='文件夹创建成功';
            $value['success']='success';
        } else {
            $value['file'] ='文件夹创建失败';
            $value['fail']='fail';
        }
    }
    else
    {
        $value['file'] ='文件夹已存在';
        $value['fail']='fail';
    }
    return $value;
}
Copy after login

Recommended related articles:

How to use PHP to return json data (code)

How to use PHP To create a soft connection (code)

The above is the detailed content of How to create a file directory in php? (Pure code). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!