Forums

mkdir permissions issue

andypooz 20 Aug, 2011
I am completely new to mkdir, and i can't seem to get it to work, so I'm hoping someone will suggest things I might try:

I am using chronoforms V4 and a custom code block to run a bit of code (This isn't really a chronoforms question, but I'll try to push my luck anyway as you're a smart bunch on here)

I am trying this:

$schdir = "../../../../sites/" . $form->data['shortname'];
if (mkdir($schdir, 0777)) {
echo "Made"; } else { echo "Not made"; }
echo dirname( __FILE__ );
echo "<br/>" . $schdir;
die();



to see if my nkdir is working (and it aint!)

I am getting as a response:

Not made
/home/sites/websitesfast.co.uk/public_html/host/administrator/components/com_chronoforms/form_actions/custom_code
../../../../sites/frecol



So, I have checked the obvious:
The folder is not being made
$form->data['shortname'] is getting the appropriate value from the form
echo dirname( __FILE__ ); shows I'm 4 directories up from where I want to be
../../../../sites/frecol is the path to the directory I want to create ('host' is my site root folder, host/sites/ already exists and is 0777 )

The error message I get from my hosting console is
[Sat Aug 20 15:45:09 2011] [error] [client 158.94.64.113] PHP Warning:  mkdir() [<a href='function.mkdir'>function.mkdir</a>]: Permission denied in /home/sites/websitesfast.co.uk/public_html/host/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(17) : eval()'d code on line 3, referer: http://www.websitesfast.co.uk/host/index.php?option=com_chronoforms&chronoform=schoolmaster_signup



I wonder...
Can I move up the folders like that? ../../ ? I know the path should be relative so I'm assuming using jhtml to get the site root will not work
Is there something else, permissions-wise that I'm unaware of?

If you have things I can try or places to look for more clues about why it's failing, then please chip in.
Many thanks
Andy
GreyHead 20 Aug, 2011
Hi Andy,

In general it's best never to use relative paths or URLs in Joomla! as often you can't be certain what the current folder is when the code runs. Note that the error message show a path realtive to the chronoforms form_actions folder.

Joomla! has some built-in JFolder & JFile methods that are easier to use, and possibly better, than mkdir. Docs are here for JFile; and here for JFolder. There's an example here.

You should also be careful about separators in Path names, some systems use \ and others / - to be safe use the defined term DS so your path looks like
JPATH_SITE.DS.'sites'.DS.'frecol'.DS


Hopefully that's enough to get you going.

Bob
andypooz 20 Aug, 2011
Thanks Bob. I followed your suggestions and it worked straight away. An electronic beer should be making its way to you as I type.
Cheers!
Andy
This topic is locked and no more replies can be posted.