username.'/')){ echo "-----------MKDIR-----------"; if (!mkdir('/'.$form->username.'/',0777)){ echo"CREATE FOLDER IMPOSSIBLE !"; }else{ echo"CREATE FOLDER SUCCESSFULLY !"; }}?>I have tried with mode "View" and mode "Controller" but always the same error.Here is the error I have:Warning: mkdir() [function.mkdir]: Permission denied in /administrator/components/com_chronoforms/form_actions/custom_code/cfaction_custom_code.php(14) : eval()'d code on line 6CREATE FOLDER IMPOSSIBLE !But I a trying to create the folder at the root and not in the folder specified in the error message. And I have the rights 755 on this folder. I have tried with permissions 777, it doesn't work neither.Thanks in advance for your help.Kind regardss,Kevin"> Create a folder after registration - Forums

Forums

Create a folder after registration

kevinash 25 May, 2012
Hi all,

I have added some PHP code to create a folder at the root of my website when a new user is registered.

I have create an action "Custom code" on the event "On Submit" but it fail every times.

Here is the code that I have added, it's just a mkdir:

<?php
echo 'DOMAINE: '.$form->domain.'<br />';

if(!is_dir('/'.$form->username.'/')){
  echo "-----------MKDIR-----------<br/>";
  if (!mkdir('/'.$form->username.'/',0777)){
    echo"CREATE FOLDER IMPOSSIBLE !<br/>";
  }else{
    echo"CREATE FOLDER SUCCESSFULLY !<br/>";
  }
}
?>


I have tried with mode "View" and mode "Controller" but always the same error.

Here is the error I have:
Warning: mkdir() [function.mkdir]: Permission denied in /administrator/components/com_chronoforms/form_actions/custom_code/cfaction_custom_code.php(14) : eval()'d code on line 6
CREATE FOLDER IMPOSSIBLE !

But I a trying to create the folder at the root and not in the folder specified in the error message. And I have the rights 755 on this folder. I have tried with permissions 777, it doesn't work neither.

Thanks in advance for your help.

Kind regardss,
Kevin
GreyHead 25 May, 2012
Hi kevinash,

Where are you setting the values for $form->domain and $from->username ??

Bob
kevinash 31 May, 2012
Hi GreyHead,

Thanks for your answer and sorry for the delay.

I didn't set the values for $form->domain and $form->username. I was thinking that's done by default.
(Probably I have misunderstood what I have read in the help tab "the variable $form->form_output is available for use at both modes,...")


But even if I use an hardcoded path to create the folder, I received the same error message.

Thanks for your help.
Kind regards,
Kevin
GreyHead 31 May, 2012
Hi Kevin,

I'm not certain but I think that $form->form_output contains the Form HTML that has been constructed up to the point when the action runs. It's only useful in the On Load event.

The $form->data array will contain the form results and any other data that you have added to it. I wouldn't expect either $form->domain or $form->username to be set.

You can get the current User name from the Joomla! User object. This code will add it to the $form->data array:
<?php
$user =& JFatory::getUser();
$form->data['username'] = $user->username;
?>

Bob
kevinash 31 May, 2012
Thank you Bob, that resolves a part of my problem.

Do you have an idea for the problem with the mkdir() ?

Thank you again.

Kind regards,
Kevin
GreyHead 31 May, 2012
Hi Kevin,

It probably will fail with an invalid $from->username in there. Does it work if you try a fixed value for testing? If so then you need to fix the problem with the username variable.

Bob
kevinash 31 May, 2012
No, it doesn't work with a fix value.

Thanks
Kevin
GreyHead 01 Jun, 2012
Hi Kevin,

Then it sounds increasingly like a problem with permissions. Sometimes the 'Joomla' user doesn't have the same permsissions to create files as the FTP user.

Bob
kevinash 01 Jun, 2012
Thanks Bob,

I was afraid that's a problem of permission :?

What do you advise me to do ?
Maybe on the custom code of Chronoforms I can do an "include" of an other php file which will do the mkdir ? (Hope I'm clear enough).

Or can I change permission of Joomla user ?

Thanks.
Kevin
GreyHead 01 Jun, 2012
Hi Kevin,

I'd suggest that you try creating your folder somewhere other than in the root folder. See if it will work in the ChronoForms uploads folder for example.

You might also try using the Joomla! JFile and JFolder methods - I think that you can set those to output the folder chmod settings that they see so you'd get a better idea of what is happening. If you do this make sure that you disable FTP in the site Global Configuration as that can cause similar problems.

Bob
kevinash 01 Jun, 2012
Bob,

Yes it works in other folder.

I will do it like that.

Thanks for your help again.

Kind regards,
Kevin
This topic is locked and no more replies can be posted.