A little introducion.
Today I was making a Joomla site for my customer. He requested to add an application from to his site. So, I thought why not to use ChronoForms. Ok downloaded, installed, looked into the manual, did everything. Added a file field, added enctype etc. Trying to submit... Dang, E-mail not sent... OK, I thought... Let's debug this. So I went to chronocontact.php and found a neat little function called
handle_uploaded_files
in that function there is a var $fileperms = "0000";
and then theres is an if statement if ( strlen($mosConfig_fileperms) > 0 ) {
$fileperms = octdec($mosConfig_fileperms);
}
I though ok ... Let's see our $mosConfig_fileperms var in configuration.php . And dang ! It was
$mosConfig_fileperms = '';
AHA ! Got you ! Basically because of that var the file was uploaded with 0000 CHMOD, that means that only webserver root can do something with it, that means that mosMail function wasn't even able to read this file, hence the "E-mail not send" error, since I dont have any root .. I changed it to 0644 so it became like this
$mosConfig_fileperms = '0644';
And voila! "E-mail sent!" I'm happy, customer happy, everyone is happy.
SOLUTION
Short solution for those who don't wanna read all the text. All you need to do, is change $mosConfig_fileperms in your configuration.php to '0644' if it is ''. So it must look like that
$mosConfig_fileperms = '0644';
P.S Sorry for my English, not a native speaker.<br><br>Post edited by: JohnieWalker, at: 2008/01/30 21:09
Great debug, thank you. I think we can add a check for this into ChronoForms that would write in a default value if the config value is not set.
Bob
Could that also explain why file upload that also sends an email works on some local servers and not remote because of permissions?<br><br>Post edited by: GreyHead, at: 2008/02/01 23:45
I followed your instructions, however, when I use 0644 the file is actually flagged as 204 and appends a T at the end of the permissions -w----r-- T. File still 0KB when I download.
I tried changing it to 777 and it flags the file as -wxrw-wt .
File is still 0 KB when I download. I've never seen the t before.
Any ideas?
Thanks in advance for any help you can offer.
Ruth
Just to be clear - showing up as 33kb on the website - this is in the Uploads folder so the upload has completed successfully?
Bob
Yes, the file shows up as 33KB in the Upload folder.
Now I need to download the file to my local PC for use.
The script was edited to set the permissions to 644. But when I look at the file in FTP, the permissions are shown as -w----r-T.
If I try to download FTP gives the 550 error message: Cannot open, permission denied.
So I went back into the script and changed the rights to 777. Now when I upload a new file it shows up in the Upload folder with -wxrw--wt. If I try to FTP the file to my local PC I still get the 550 error message: Cannot open, permission denied.
How can I download the file for use on my PC? Is it an ownership issue?
Thanks, Ruth
I followed the instructions for changing the rights to the file to 644. When the file uploads it now shows the rights as:
-w----r--t or 204
I edited the script to change them to 777. When the file uploads it shows the rights as: -wxrw----t (362).
In both cases, when I try to ftp the file to my local PC I get :
550 Can't open 20080208085806_chronoforms.txt: Permission denied
Error: Download failed
How can I download the file so it can be used locally?
Thanks,
Ruth
sorry if this question is already asked but i just fly over the thread because read a lot of english text is exertive...
i searched in diffrent other forums and looked for finished scripts with google but i didn't found... hope you can help me
Add this code to the html box : <input type="file" name="file"> , now follow the uploads section tab guidelines and you can look for some extra details too in the FAQs section here on the site or search the forums for "type="file"" and you will get lots of code results posted by users about this🙂
Cheers
Max
Now nearly everything works perfectly... the user can choose the file which he'd like to upload and can klick on submit and there is no error message anymore🙂
but now there is a problem at the backend...
i get the form with name, description and everything i set. but the file is given with the local path e.g.
C\\files\\myexample.tar.gz
how can i get the path on the server? or isn't the file uploaded yet?<br><br>Post edited by: Vermillion, at: 2008/04/01 10:08
Hi Bob and thanks for your reply.
Yes, the file shows up as 33KB in the Upload folder.
Now I need to download the file to my local PC for use.
The script was edited to set the permissions to 644. But when I look at the file in FTP, the permissions are shown as -w----r-T.
If I try to download FTP gives the 550 error message: Cannot open, permission denied.
So I went back into the script and changed the rights to 777. Now when I upload a new file it shows up in the Upload folder with -wxrw--wt. If I try to FTP the file to my local PC I still get the 550 error message: Cannot open, permission denied.
How can I download the file for use on my PC? Is it an ownership issue?
Thanks, Ruth
I had exactly the same problem (ChonoForms v2.5 J1.5_RC2.1) and discovered a bug in file "chronocontact.php"
change somewhere line 550
$fileperms = "0644";
into
$fileperms = 0644;
Rationale: $fileperms is used as parameter of function chmod(), and should be an integer, not a string type.
That should solve the issue.<br><br>Post edited by: Actor, at: 2008/04/04 02:42
And I guess too that you don't get the file attached at the email ? do you ? did you add the enctype="multipart/form-data" to the form tag attachment field ?
Thanks again Actor😉
Max
I am using Joomla 1.5 version of chronoforms and I can't get file uploads to work.
I have checked in the chronoforms.php and the fileperms is commented out:
function handle_uploaded_files($uploadedfile, $filename, $limits = TRUE, $directory = FALSE)
{
//global $mosConfig_absolute_path, $mosConfig_fileperms;
//$fileperms = "0644";
/*if ( strlen($mosConfig_fileperms) > 0 ) {
$fileperms = octdec($mosConfig_fileperms);
}*/
$uploaded_files = "";
$upload_path = JPATH_SITE.'/components/com_chronocontact/upload/';
One thing though - I would like for the images to show up in the email instead of just attachments. I have tried using the following in my custom email:
<img src="<mysite>/components/com_chronocontact/upload{image1}"></img>
However, it appears that this passes in the original image name instead of the name of the image after the date is appended to it. Is there a {keyword} I can use in the custom email to get the name of the uploaded image?
Thanks!
Try this snippet (replacing field_name with the name of your upload field):
<?php
global $mosConfig_live_site;
$file = basename($attachments['field_name']);
$upload_path = $mosConfig_live_site.'/components/com_chronocontact/upload/';
?>
<img src="<?php echo $upload_path.$file; ?>"></img>
Bob
Later: added the 'global' line to fix the problem reported in the next post.
Anyway - thanks! You're the best!
I echoed out my file permissions.
File perms= 0777
Warning: move_uploaded_file(/home/.../public_html/components/com_chronocontact/upload/20080513222202_Zorro.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/.../public_html/components/com_chronocontact/chronocontact.php on line 538
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phprIRRN5' to '/home/.../public_html/components/com_chronocontact/upload/20080513222202_Zorro.jpg' in /home/.../public_html/components/com_chronocontact/chronocontact.php on line 538
Warning: chmod() [function.chmod]: No such file or directory in /home/.../public_html/components/com_chronocontact/chronocontact.php on line 540
Here is what I get when i turn the debug message on:
_POST: Array ( [creation_user_id] => 66 [status] => A [cat] => Home Decor [title] => cvnb [summary] => cvbn [description] => cvbn [cost] => [time] => )
I will send whomever a backup of the form to an email if need be.
The debug doesn't help here as it doesn't include the $_FILES array.
I think there was a small fix in a recent ChronoForms release so please update to the latest version.
You can also send a Form Backup to the address in my sig but this will only confirm if there is a problem with the form - permission problems are site / server related.
Bob
Thanks a lot for your quick response and help. The update seemed to do the trick. I can now see the files uploaded on the server. The issue that I see now is that when I go to view the form data in the admin I'm not seeing the file name displayed. I'm trying to get into the database now to see if it was inserted in the table, but I think the server is down. Is there some kind of display limit when viewing the form data? The filename is kinda long, because it gets generated.
There shouldn't be any problem viewing the form data (if the MySQL server is down then your site won't work at all).
Please will you copy and post the code from your form Autogenerated code tab here to check that the file is included there.
Bob
PS I sometimes find that the free EasySQL Joomla Extension is a simple way to look at database tables.
Here is the auto-generated code. The "photofile" is the name in the form. It was working before, now it stopped once I upgraded.
<?php
$database =& JFactory::getDBO();
$database->setQuery( "INSERT INTO #__chronoforms_3 VALUES (
'' , '". date('Y-m-d')." - ".date("H:i:s")."', '".$_SERVER['REMOTE_ADDR']."' , '".$_POST['cat']."' , '".$_POST['title']."' , '".$_POST['summary']."' , '".$_POST['description']."' , '".$_POST['cost']."' , '".$_POST['time']."' , '".$_POST['photofile']."', '".$_POST['creation_user_id']."' , '".$_POST['status']."');" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>
Sorry, I missed this post. Try replacing
$_POST['photofile']
with$_FILES[$allowed_s2[0]]['name']
Bob
all made as written http://www.chronoengine.com/component/option,com_easyfaq/task,view/id,29/Itemid,38/
Everything works fine,
mail message comes with an attachment
I have a question:
I put enctype='multipart/form-data' in the Form tag attachment field on the General tab.
How to add verification of javascript onSubmit="return competition(this)" ??? [file name=competition.cfbak size=5540]http://www.chronoengine.com/images/fbfiles/files/competition.cfbak[/file]
Just add it in the same box with a space between the two. Whatever goes in there is added into the <form> tag.
Bob
PS Or you could use ChronoForms validation instead of your own JavaScript, it will work just as well.
everything worked perfectly
sorry OFFTOP
Where can I find how to set ChronoForms validation in the FAQ? or manual
In the Forms Manager, click the Validation tab. Set Validation to ON, select the Mootools library of you have Joomla 1.5 (or are using other Mootools based extensions) put a comma separated list of fieldnames in the 'required' box and save the form.
Most of the validation options are self-evident, there are some wrinkles using validate-one-required though.
Bob
First of all, I'd like to thank you for helping me out. I tried changing the autogenerated code to what you said, but now it won't write anything in the database.
I have also started to modify the chronocontact.php file itself. I am trying to generate thumbnails for the images that are uploaded. Then store the original image and thumbnail in a user directory on the server. Then write each uploaded file to the database table. I was trying to just add that code in the onSubmit section, but it wasn't recognizing anything, so that's when I started to play around in the chronocontacts.php file. I have been able to generate the thumbnail, but have not been able to write anything to the database. Perhaps I need to just write a separate SQL query to write to the database after the initial auto generated code is executed. My problem is, that I don't really know the flow of how chronoforms works. I also don't want to be reinventing the wheel or anything, so if there is already some way to auto generate thumbnails and store in the database then I'm all for it, but none that I have found. Any ideas, suggestions?
There is nothing in ChronoForms to generate thumbnails - or to do anything with images, or to store them in the database. I'm sure all those things are possible though.
You should not need to hack the ChronoForms code to do so though - almost everything is possible using the code boxes.
The flow is pretty simple. The form html and JavaScript are show n when the form is displayed. When the form is submitted the default sequence is:[list]
I tend to put custom code to do with the email in the OnSubmit before box and anything else in the OnSubmit after. The boxes are called through eval and you may need to declare any global variables you want to use.
Bob
I have reverted to my original auto-generated code which I have posted below, however nothing is getting written to the database at all anymore. Before Everything except the photofile was getting written, now nothing is.
<?php
$database =& JFactory::getDBO();
$database->setQuery( "INSERT INTO #__chronoforms_3 VALUES (
'' , '". date('Y-m-d')." - ".date("H:i:s")."', '".$_SERVER['REMOTE_ADDR']."' , '".$_POST['cat']."' , '".$_POST['title']."' , '".$_POST['summary']."' , '".$_POST['description']."' , '".$_POST['cost']."' , '".$_POST['time']."' , '".$_POST['photofile']."', '".$_POST['creation_user_id']."' , '".$_POST['status']."');" );
if (!$database->query()) {
echo " alert('".$database->getErrorMsg()."'); window.history.go(-1);
";
}
?>
I would have probably let ChronoForms upload the files and then moved them on to the dynamic folder, either will work but hacking the code always makes upgrading more difficult.
I'd echo out the sql and test it in PHPMyAdmin. What is there looks OK to me. Is the table name still correct?
Bob
To get the sql you have to make a small change to Max's default code.
$sql = "INSERT INTO #__chronoforms_3 VALUES (
'' , '". date('Y-m-d')." - ".date("H:i:s")."', '".$_SERVER['REMOTE_ADDR']."' , '".$_POST['cat']."' , '".$_POST['title']."' , '".$_POST['summary']."' , '".$_POST['description']."' , '".$_POST['cost']."' , '".$_POST['time']."' , '".$_POST['photofile']."', '".$_POST['creation_user_id']."' , '".$_POST['status']."');";
if ( $debug ) {
echo "sql: $sql <br />;
}
setQuery( $sql );
if (!$database->query()) {
echo " alert('".$database->getErrorMsg()."'); window.history.go(-1);
";
}
?>
this just pulls the sql into a separate variable and show sit in DeBug mode. You should then be able to copy and paste it into PHPMyAdmin and see if it runs or not. You will need to manually change the table prefix, probably from #__ to jos_
Bob
I tried what you said, turned on the Debug mode in the Chronoforms component under the General tab. Nothing is getting echoed out. The DEBUG option under the General tab says that I'm supposed to see some kind of diagnostic output, but I don't see anything. I tried turning the system debug on in the Global Configuration settings and I received an error when trying to go to my form page. It said the jos_chrono_contact_plugins table does not exist. I did not delete this table, so was it just never created? Why does the form show up when the system debug is off, but produce an error when it is on?
If the debug info doesn't show then you probably have a Redirect URL in the Form URLs tab, please remove it temporarily.
Sorry, but I've no idea about the site debug results. If you want an easy way of looking at the MySQL tables then I recommend EasySQL, a very neat little table browser extension for Joomla.
Bob
Thanks for the quick reply. Yes, I did have a redirect URL, thanks for the hint. I actually have been using the EasySQL you recommended to me earlier, pretty neat. I submitted my form and I found out why nothing was getting written to the table. The auto generated code is not even being executed. This is the error that I am receiving
"Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../components/com_chronocontact/chronocontact.php(571) : eval()'d code on line 14"
Here is that block of code, which I did not touch. It looks like there is nothing wrong with it either.
/**
* Run the SQL query if there is one
*/
if($paramsvalues->autogenerated_order == $ixx){
if ( !empty($rows[0]->autogenerated) ) {
eval( "?>".$rows[0]->autogenerated );
}
}
The problem is in the eval()'d code - in this case it's the code in the AutoGenerated tab of your form - check line 14 there : most likely a missing ;
Bob
Thanks a ton for all of your help. This has been a real learning experience for me and I thank you for that. My project is almost complete, but I seem to be having one more issue. Nothing gets written to the database when I have the redirect URL set. It's not any special kind of url or anything, just a URL to an article. If I take off the redirect everything works perfectly, but it's just an empty white box if I do that. Do you know what could be causing this? Thanks in advance.
Thanks.
There's something odd happening with that Redirect. A couple of people have mentioned it but I can't see anything wrong, and Max hasn't suggested anything either.
Please will you take a Backup Copy of your form from the Forms Manager and a copy of your chronocontact.php file and email both of them to me at the address in my sig and I'll take a look.
Bob
I sent the stuff over to your email yesterday. Just wondering if you had a chance to take a look at it yet.
All safely received, next on the list to look at. Back shortly.
Bob
Confirming that you have a buggy version of chronocontact.php please download the fixed version from this post
. . . now to find out where you got it from, the downloads were fixed a while back, or so I thought.
Bob
Thanks so much! That fixed it. I downloaded the upgrade package. Again, thanks a bunch for all of your patience and help, you are awesome! :cheer:
The original code did this after picking up the value from $mosConfig_fileperms.
However, even after making sure the decimal-to-octal conversion was taking place, and the proper permissions were showing up in the uploaded file, I am still not getting the file posting to its column in the database table jos_chronoforms_x.
Can someone point me to the code that does the insert to this table? I am so far unable to find it in chronocontact.php, or anywhere.
Hi redrings,
Have you checked this FAQ??
Bob
Hi Bob,
Big problem with this FAQ.
Check in your configuration.php file that there is a value set for $mosconfig_fileperms; if it is blank or set to '0000' please set it to 0644.
The only configuration.php file I have in my directory is the main one for Joomla itself. It does not list $mosconfig_fileperms; anywhere within it.
Check that "chmod new files" is ticked in Joomla's Global Configuration.
I don't see this anywhere in the Joomla control panel. Am I not looking in the right place?
Otherwise, what is happening is that the server is telling me my .jpg file type is not allowed. Where do I change something to allow that setting?
Otherwise, the form is installed and looks great.
Cheers
Max
Hi, remove the chmod line from the upload function!
Cheers
Max
Max,
Thanks for the tip, but could you be more specific? Are you talking about the function within the configuration.php file?
If so, the only place that has anything about chmod was commented out.
Here's what I now have:
function handle_uploaded_files($uploadedfile, $filename, $limits = TRUE, $directory = TRUE)
{
global $mosConfig_absolute_path, $mosConfig_fileperms;
$fileperms = 0644;
if ( strlen($mosConfig_fileperms) > 0 ) {
$fileperms = octdec($mosConfig_fileperms);
}
$uploaded_files = "";
$upload_path = JPATH_SITE.'/components/com_chronocontact/upload/';
if ( is_file($uploadedfile) ) {
$targetfile = $upload_path.$filename;
while ( file_exists($targetfile) ) {
$targetfile = $upload_path.rand(1,1000).'_'.$filename;
}
move_uploaded_file($uploadedfile, $targetfile);
if ( strlen($fileperms) > 0 ) {
chmod($targetfile, $fileperms);
}
$uploaded_files = $targetfile;
}
return $uploaded_files;
}
So far, I've removed the quotes from around 0644. I've uncommented the chmod line. I don't want to email a file. I want a user to upload it to a directory.
I have the form installed, and when I click submit, I do get a confirmation email, but no file is transferred.
Is there some other setting I need to change?
And I've read the faq, and I've made sure I've followed the suggestions.
Randy
chmod($targetfile, $fileperms);
what are the results ?
Max
function handle_uploaded_files($uploadedfile, $filename, $limits = TRUE, $directory = FALSE)
{
global $mosConfig_absolute_path, $mosConfig_fileperms;
$fileperms = 0644;
if ( strlen($mosConfig_fileperms) > 0 ) {
$fileperms = octdec($mosConfig_fileperms);
}
$uploaded_files = "";
$upload_path = JPATH_SITE.'/components/com_chronocontact/upload/';
if ( is_file($uploadedfile) ) {
$targetfile = $upload_path.$filename;
while ( file_exists($targetfile) ) {
$targetfile = $upload_path.rand(1,1000).'_'.$filename;
}
move_uploaded_file($uploadedfile, $targetfile);
// if ( strlen($fileperms) > 0 ) {
// chmod($targetfile, $fileperms);
//}
$uploaded_files = $targetfile;
}
return $uploaded_files;
}
I get to the blank site page fine, but nothing appears in the upload directory. No other obvious errors reported.
I think you'll need to add some debug code to show what's happeining here. Just echo some of the variables back to map the progress of the function.
Bob
to clear Bob's words, just add some statements like :
echo '1';
between lines, so you know that all is going fine by counting the output later, did you check the folders permissions ?
What kind of files are you uploading and what do you want to do with them?
You can make the file downloadable by creating a link using the file upload path and the file name.
Bob
I have the same problem of socialite7. The visitors uploads a "pdf" files but when viewing them from the control panel I get the uploaded file as the name of the file but without a link. I want to be able to click on it and download the "pdf" file.
This will require a core file hack, its posted in the forums before!
Regards,
Max
I did the hack myself and worked fine.