Codeigniter make directory if not exist

create folder and upload file in codeigniter
mkdir
php mkdir
codeigniter helper folder
create directory if not exists php
codeigniter get directory path
codeigniter create folder on server
codeigniter folder

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);

}

and I got an error like

Message: mkdir(): Invalid argument

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

Thanks for any response.

The date format wil have specail chars like - and :

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);

}

or use as elavarasan lee said use:

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

Codeigniter make directory if not exist, Problem :** How to check if a directory exist or not? If not, how to create a directory? **NOTE :** This solution should be applicable for all PHP  When a page is loaded, the session class will check to see if a valid session cookie is sent by the user’s browser. If a sessions cookie does not exist (or if it doesn’t match one stored on the server or has expired) a new session will be created and saved. If a valid session does exist, its information will be updated.

if(!is_dir($config['upload_path'])) mkdir($config['upload_path'], 0777, TRUE);

CodeIgniter/PHP : Create directory if does not exist example, Hi all, I have been working on a function where can create a folder on my file manger, using mkdir. I would like to know does codeigniter have a helper for that I know a helper for creating files but have not see one for creating directories There's only one rule - please don't tell anyone to go and read the  * Check if folder exist and writable. * If not exist try to create it one writable. * * @return bool * true folder has been created or exist and writable. * False folder not exist and cannot be created. */ function createWritableFolder($folder) { if($folder != '.' && $folder != '/' ) { createWritableFolder(dirname($folder)); } if (file_exists($folder))

if you are new to codeigniter and previously in php you used code for making directory like

$target_dir="../../media/profile/".date('my')."/";
    if(!file_exists($target_dir)){
        mkdir($target_dir,0777);
    }

then in codeignitor you can use only one dot for outside directory path

$target_dir="././media/profile/".date('my')."/";
    if(!file_exists($target_dir)){
        mkdir($target_dir,0777);
    }

this one solved my problem.

Making Directory PHP Codeigniter, CodeIgniter does not automatically create a directory when uploading a file to a non-existent directory. There are some work around by  In this post, i will help to check if directory exists or not before create in laravel 5 application. we can simply check if folder exist when you create new directory using File facade. File facade will provide method to check directory and create directory with permission using isDirectory() and makeDirectory().

Automatically Create Directory When Uploading With CodeIgniter , The above example will create folder profile in images folder if it does not exists. It will assign the folder permission 0755 so you can add  If the file does not already exist, then the directory containing it must be writable. Note The path is relative to your main site index.php file, NOT your controller or view files.

Codeigniter Create Directory, Don't forget to use the recursive option on Windows if creating a folder below a folder that already exists. Otherwise you may get a very confusing error message,​  check value already exists in codeigniter Callback function of codeigniter which checks whether the value already exists in particular column of table or not. This function work on add and edit both cases,it return false if value exists and return true if value not exists. following is the function that you need to put in your controller file:

mkdir - Manual, This is a quick PHP tutorial on how to create a folder or directory if it doesn't already exist. I get no errors when I enter my data and hit submit. I realize that some of the things I have done in the code are not necessary such as the tick marks. Its all been a matter of trying to see if it would fix my problem. Any suggestions as to what I can do please? UPDATE 6/20/14. It seems that trouble lies in my CREATE TABLE syntax.

Comments
  • ":" colon character is not allowed in directory name.
  • try to give complete path. and enclosed in in double quotes.
  • @elavarasanlee thanks for that info I'll try it now, and will get back to you if it fix
  • Use date('Y-m-d H.i.s') instead of ':'.
  • I have tried $date = 'abc' line two of above code, to test if date thing is my problem here, but still i got the same error
  • @kodewrecker, no problem. Glad i could help. Don't forget that you must change the date BEFORE you set it up in the codeigniter config. Or else that wil fail still ;)
  • This answer is in the Low Quality Posts review queue because it's just a line of code with no explanation. Please explain what your code does and how it answers the question.
  • Good answer doesn't need explanation. This is the best answer.