Question

I'm using below PHP code here to create a particular folder if it didn't exist. I'm using joomla 2.5

$path = my/path/goes/here;
$folder_permissions = "0755";
$folder_permissions = octdec((int)$folder_permissions);
//create folder if not exists
if (!JFolder::exists($path)){
     JFolder::create($path, $folder_permissions);          
}

But this code throws below error

JFolder::create: Could not create directory

What could be the reason for this?

Was it helpful?

Solution

2 things I think might be causing the problem:

  1. You forgot a ; on the end of octdec((int)$folder_permissions)
  2. Try removing the whole line $folder_permissions = octdec((int)$folder_permissions)

Update: This is what I used to create a simple folder:

$destination = JPATH_SITE.'/'."modules/mod_login";
$folder_name = "new_folder";
JFolder::create($destination .'/'. $folder_name, 0755);

OTHER TIPS

What could the reason be? Simple: The user that tries to create that directory doesn't have permission (or your Joomla is broken).

The user that runs the code is probably www-data (on most *nix/Apache). ALso 'nobody' or 'apache' are possible. If you have rootpermission try this:

1) become the webuser (eg www-data)

2) Jump to the directory my/path/goes/here

3) type: mkdir mynewdir

And you will probably find out that the user doesn't have sufficient permissions to do so.

edit your configuration.php file under Joomla home direcory, change:

From:

var $tmp_path = '/home/public_html/your_name/tmp';

To:

var $tmp_path = 'tmp';

and tmp should have 777 permission

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top