Forums

How to Create a Directory using $user and ChronoForms?

soliver 08 Apr, 2009
Hi Everyone,
I want to be able to create a sub directory from the $user variable
My plan is have all the users of yoursite.com to have their own sub directory. I want to use the $user variable as the subdirectory name.

For example yoursite.com after executing the form would create a subdirectory under yoursite.com thereby creating yoursite.com/$user. If the $user variable was craftman, then the directory that would be created would be yoursite.com/craftman

I have tried the following code as a test inside "Form HTML" without any results, just a blank screen. Can anyone help me out. I would really appreciate it.

<?php
$user =& JFactory::getUser();
if (file_exists("/var/www/vhosts/yoursite.com/httpdocs/$user")) {
print("Directory already exists.\n");
} else {
mkdir("/var/www/vhosts/yoursite.com/httpdocs/$user");
print("Directory created.\n");
}
?>
GreyHead 08 Apr, 2009
Hi solivar,

I have no idea if this will work but $user is an object - you need to use $user->username in the paths
mkdir("/var/www/vhosts/yoursite.com/httpdocs/".$user->username);

Bob
soliver 08 Apr, 2009
Hi Grayhead,

Thanks for offering up some help but that does not create the directory either. I have to think that there must be a way to do this? Any other ideas?

Scott
Max_admin 09 Apr, 2009
Hi Scott, 2 suggestion, don't use the variable in the dir path till you are sure its working, use any text instead, and, use the Joomla built file system functions to create this!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 09 Apr, 2009
Hi Scott,

I think that the Joomla code Max refers to is JFolder::create('path'); - see the docs here

Bob
soliver 09 Apr, 2009
Max or GrayHead,

Do you know of any examples of how this works. I did discover this while I was searching for ways to create a directory in Joomla and they show so some code but I can not make any since out of it.

Real word examples on how to create a directory in Joomla using ChronoForms would be wonderful.

Thanks

Scott
GreyHead 09 Apr, 2009
Hi Scott,

Did you check the link to the docs?
<?php
$path = 'some path';
JFolder::create($path);
?>

Bob
soliver 09 Apr, 2009
I am making some headway.

This code works but I plan to clean it up and add more as I investigate further.
<?php
//First we set up parameters (JPATH_SITE = The path to the installed Joomla! site)
//DS = is used as a directory separator.
$searchpath = JPATH_SITE . DS . "images";
 
//Then we create the subfolder called scott-testing
if ( !JFolder::create($searchpath . DS . "scott-testing") ) {
   //Throw error message and stop script
}
 
?>


I will update as I proceed

Scott
jnba 25 May, 2009
hello, i would like to implement this on my form, but i really need lots of help,
first of all where do i put this code? and is there a working example?

thanks,

john
Max_admin 26 May, 2009
Hi John,

I think that the code in Scott's last post should work, you need to put in the onsubmit after email box if you want the folder to be created when the user submits the form!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jnba 27 May, 2009
hi max,

i have copied and pasted the code, inserted my path etc.. but nothing, what i would like to accomplish is have the user upload to their directory all their images so its not so confusing.

Theres a ton of stuff to do with the form i need just no time to go through every detail at the moment, but this one is crucial for now.


Thanks,

john
Max_admin 27 May, 2009
Hi John,

When the form is submitted the code below should create a folder called "scott-testing" under the images directory, does it work ?


<?php
//First we set up parameters (JPATH_SITE = The path to the installed Joomla! site)
//DS = is used as a directory separator.
$searchpath = JPATH_SITE . DS . "images";

//Then we create the subfolder called scott-testing
if ( !JFolder::create($searchpath . DS . "scott-testing") ) {
//Throw error message and stop script
}

?>


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jnba 28 May, 2009
hi max,

its not creating it.. should I add my path here $searchpath = JPATH_SITE . DS . "images";?

JPATH_SITE been my site directory?
jnba 29 May, 2009
hello again,


Max, Im sorry the code does work, as a newbie i was looking in wrong places.

Well now how can i now add the directory as the username instead of scott_testing and that the files they upload go into that directory?



thanks,

john
jnba 29 May, 2009
ok... i have created the directory with username..

now,

is it possible to upload the files to the specified user that was created?

this is what i have now.. based on scotts and greyheads posts..

<?php
//First we set up parameters (JPATH_SITE = The path to the installed Joomla! site)
//DS = is used as a directory separator.
$user= & JFactory::getUser();
$searchpath = JPATH_SITE . DS . "mi1erapic/empleados";

//Then we create the subfolder based on username
if ( !JFolder::create($searchpath . DS . "$user->username") ) {
   //Throw error message and stop script
}

?>
Max_admin 01 Jun, 2009
Hi John,

Great, now add your code to the OnSubmit Before Email box and add at the bottom of it this line:

$MyForm->setFormParam('uploadpath', $searchpath . DS . "$user->username".DS);


then test, you should have at least one email setup at your form for the onsubmit before email code to work !

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jnba 03 Jun, 2009
hi max,

I have tried but still gets copied to default path specified.

is this how it shoud be..?:
<?php
//First we set up parameters (JPATH_SITE = The path to the installed Joomla! site)
//DS = is used as a directory separator.
$user = & JFactory::getUser();
$searchpath = JPATH_SITE . DS . "imagenes/empleados";

//Then we create the subfolder called scott-testing

if ( !JFolder::create($searchpath . DS . "$user->username") )
{
   //Throw error message and stop script
}
$MyForm->setFormParam('uploadpath', $searchpath . DS . "$user->username".DS);

?>


I have 15 upload fields which may or may not be used when they add a few large images lets say at 1-3mb files i think it timesout and get a "you may not access this url" after maybe 8-10 minutes, doesn't send email nor upload files at that moment, but if i disable attachments it will go ok, the reason its enabled is beacause I need to know who uploaded what as it will be a few people uploading files with filled out forms, If its possible to have them upload to their home directory based on Username and maybe add the username to the files uploaded then I will disable the email attachments since its easier and faster.

another advice i would need if its faster to zip the files or user directory and upld to specified dir. thats maybe an option, adding the username to the file instead of date/time.


I gladly appreciate your help.

thanks,

John
Max_admin 05 Jun, 2009
Hi John,

Sorry I have been off for a few days working in the new release!

first thing, please get the new release!

lets do everything now step y step!

to fix the timeout which causes the you are not allowed message, turn OFF the checkToken in the general tab!

are you trying to send the uploads to your dynamically created folder ? if so then you need to set the form instance to "same instance" in the general tab and place your code above in the Extra1 box in the form code tab! then you need to put this in the submit url field under the general tab:

index.php?option=com_chronocontact&chronoformname=your_form_name&task=send&action=extra

note that you need to add your form name!

the above solution should work but as you can see its tricky and some problems may arise so let me know!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jnba 05 Jun, 2009
aWesome!.. Max,


it created the Directory and copied the files to the specified users directory!😀 😀 😀

early call, when i went to check email all my fields are blank.. I did remove the code from the onSubmit before, could that be the problem?



Not one error, now im trying a big file upload to test the timeout error.

Now how would i go about adding the username to the file instead of having the date/time?
jnba 05 Jun, 2009
False alarm,

mysteriously i tested again and field values are correct.

sorry.

john
This topic is locked and no more replies can be posted.