Codeigniter make目录(如果不存在) [英] Codeigniter make directory if not exist

查看:100
本文介绍了Codeigniter make目录(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我这个忙.基本上我使用了codeigniter的文件上传类,链接是 此处 而且效果很好!但是我需要知道如何在此默认的上载路径$config['upload_path'] = './uploads/'中创建目录,文件夹的名称是今天的日期,这是我的示例代码.

Hi can anyone help me with this. Basically I used the file uploading class of codeigniter the link is here and it works fine! but I need to know how to create directory inside this default upload path $config['upload_path'] = './uploads/' the name of the folder is the date today this is my sample code.

date_default_timezone_set('Asia/Manila');
$date = date('Y-m-d H:i:s');

    $config['upload_path'] = './uploads/'.$date;
    $config['allowed_types'] = 'jpg|jpeg|gif|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';


if (!is_dir('uploads/'.$date)) {
mkdir('./uploads/' . $date, 0777, TRUE);

}

我收到了类似的错误

Message: mkdir(): Invalid argument

我搜索了解决方法,他们说这个0777 CI权限可以,但仍然对我不起作用.

I search how it will be fix and they say this 0777 CI permission will do, but still it won't work for me.

感谢您的回复.

推荐答案

日期格式将包含特殊字符,如-:

The date format wil have specail chars like - and :

我不确定-,但是在地图上不允许:.因此,您必须将该字符删除$date.

I'm not sure about the - but : is not allowed on an map. So you have to delete that char out $date.

$date = str_replace( ':', '', $date);
if (!is_dir('uploads/'.$date)) {
    mkdir('./uploads/' . $date, 0777, TRUE);

}

或用作 elavarasan lee 表示使用:

date('Y-m-d H.i.s')

这篇关于Codeigniter make目录(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆