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");
}
?>
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
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.
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
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
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.
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
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.
hi max,
its not creating it.. should I add my path here $searchpath = JPATH_SITE . DS . "images";?
JPATH_SITE been my site directory?
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
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.
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.
False alarm,
mysteriously i tested again and field values are correct.
sorry.
john