I'm getting this when I submit a form with a file attached:
To save you looking, here's the code from line 39:
And here is the form setting:
[attachment=0]file_upload_img.png[/attachment]
What am I doing wrong?
Fatal error: Cannot pass parameter 2 by reference in /home/anthon9/public_html/administrator/components/com_chronoforms/form_actions/upload_files/upload_files.php on line 39
To save you looking, here's the code from line 39:
if(!JFile::write($upload_path.DS.'index.html', 'NULL')){
JError::raiseWarning(100, 'Couldn\'t create upload directroy 2');
$this->events['fail'] = 1;
return;
}
And here is the form setting:
[attachment=0]file_upload_img.png[/attachment]
What am I doing wrong?
Hi nicholashg,
I don't understand the error. The snippet does add an extra DS (or /) and the 'NULL' is a bit odd but neither should cause this error.
Try replacing the code chunk with this version.
Bob
I don't understand the error. The snippet does add an extra DS (or /) and the 'NULL' is a bit odd but neither should cause this error.
Try replacing the code chunk with this version.
if ( !JFile::write($upload_path.'index.html', '<html><body bgcolor="#FFFFFF"></body></html>') ) {
JError::raiseWarning(100, "Couldn't write to upload folder");
$this->events['fail'] = 1;
return;
}
Bob
Hi Bob,
This produces exactly the same error.
Changing the OnSubmit events order doesn't change anything either.
When the form is accessed from the Frontend View link in admin, it produces the error but saves other data.
When the form is accessed via a Chronoforms Display Form menu link, there is no error reported, no data saved either.
Not sure what that suggests.
I made a second simple upload form to make sure I was doing nothing stupid and noticed that no upload directory has been created for the second form, although a directory exists for the first test. In every other respect, the forms behave (or misbehave) in the same way. Do you know how/when this directory is created?
I've got to get this working somehow …
Nick
This produces exactly the same error.
Changing the OnSubmit events order doesn't change anything either.
When the form is accessed from the Frontend View link in admin, it produces the error but saves other data.
When the form is accessed via a Chronoforms Display Form menu link, there is no error reported, no data saved either.
Not sure what that suggests.
I made a second simple upload form to make sure I was doing nothing stupid and noticed that no upload directory has been created for the second form, although a directory exists for the first test. In every other respect, the forms behave (or misbehave) in the same way. Do you know how/when this directory is created?
I've got to get this working somehow …
Nick
Sorry - the upload directory HAS been created, I didn't refresh my ftp.
N
N
Hi Bob & Nick,
From my experience, that kind of error message means that you are using a function/method that expects a parameter to be passed by reference (variable-name is prefixed by & ), and you pass a literal value (string, integer, etc) instead.
Passing by reference means that you hand a reference (kind of like a pointer in C) to a variable, rather than a copy of the value. This allows thef function/method to alter the variable directly, which is reflected at the higher context once the function returns.
In this case, try putting the string in a variable, and use the variable when calling JFile::write().
/Fredrik
From my experience, that kind of error message means that you are using a function/method that expects a parameter to be passed by reference (variable-name is prefixed by & ), and you pass a literal value (string, integer, etc) instead.
Passing by reference means that you hand a reference (kind of like a pointer in C) to a variable, rather than a copy of the value. This allows thef function/method to alter the variable directly, which is reflected at the higher context once the function returns.
In this case, try putting the string in a variable, and use the variable when calling JFile::write().
/Fredrik
Hi Fredrik & Nick,
I think that in this case the error is the other way round - it's refusing to accept a value passed by reference and looking for a literal value. The problem I have is that, as far as I can see, nothing here is being passed by reference (and the code worked fine last time I tested it).
I don't have time to look further today (a 90th birthday party to go to); I'll look again when I have more time.
Bob
I think that in this case the error is the other way round - it's refusing to accept a value passed by reference and looking for a literal value. The problem I have is that, as far as I can see, nothing here is being passed by reference (and the code worked fine last time I tested it).
I don't have time to look further today (a 90th birthday party to go to); I'll look again when I have more time.
Bob
Thanks both,
The only other thing I can add is this:
Running Chronoforms_J1.6_V4_RC1.7 on a localhost produces a blank page rather than an error message, but otherwise with the same results as running the same setup on the remote server.
Running Chronoforms_V4_RC1.6 under J1.5 on the same localhost works fine.
So a similar error arises under J1.6_V4_RC1.7 in both installations.
Perhaps that eliminates some things?
Nick
The only other thing I can add is this:
Running Chronoforms_J1.6_V4_RC1.7 on a localhost produces a blank page rather than an error message, but otherwise with the same results as running the same setup on the remote server.
Running Chronoforms_V4_RC1.6 under J1.5 on the same localhost works fine.
So a similar error arises under J1.6_V4_RC1.7 in both installations.
Perhaps that eliminates some things?
Nick
Hi again,
With Joomla 1.6.1, the JFile::write() method has a new footprint:
Thus, with Joomla 1.5.x the following will work:
However, with J1.6, you'll have to use something like this instead:
And no, it's not a case of "the other way round" - passing a reference of a variable to a function expecting an immediate value works well enough; the value of the referenced variable will be provided to the function as the argument variable, just as if the function/method footprint required the variable to be passed by reference in the first place..
/Fredrik
With Joomla 1.6.1, the JFile::write() method has a new footprint:
public static function write($file, &$buffer, $use_streams=false)
Thus, with Joomla 1.5.x the following will work:
if(!JFile::write($upload_path.DS.'index.html', 'NULL')){
JError::raiseWarning(100, 'Couldn\'t create upload directroy 2');
$this->events['fail'] = 1;
return;
}
However, with J1.6, you'll have to use something like this instead:
$content = '<html><body bgcolor="#ffffff"></body></html>';
if(!JFile::write($upload_path.DS.'index.html', $content)){
JError::raiseWarning(100, 'Couldn\'t create upload directroy 2');
$this->events['fail'] = 1;
return;
}
And no, it's not a case of "the other way round" - passing a reference of a variable to a function expecting an immediate value works well enough; the value of the referenced variable will be provided to the function as the argument variable, just as if the function/method footprint required the variable to be passed by reference in the first place..
/Fredrik
Thank you Fredrik,
The errors no longer appear but the file upload still doesn't happen (no name in DB, no file transmitted).
Other data saves OK.
Maybe there's more that needs reworking in the upload_files.php document?
I'm not skilled enough to do this.
I would really like to know if anyone else is having a problem with this issue. Can I be the only person who's tried this (I don't think so).
Nick
The errors no longer appear but the file upload still doesn't happen (no name in DB, no file transmitted).
Other data saves OK.
Maybe there's more that needs reworking in the upload_files.php document?
I'm not skilled enough to do this.
I would really like to know if anyone else is having a problem with this issue. Can I be the only person who's tried this (I don't think so).
Nick
Hi Nick,
I just tested with Fredrik's code and the file upload appears to work OK.
By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.
Bob
I just tested with Fredrik's code and the file upload appears to work OK.
By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.
Bob
Hi Nick,
Appears to work Ok now, I moved the file upload before the DB Save.
Bob
Appears to work Ok now, I moved the file upload before the DB Save.
Bob
Bob,
I'm sure I did the same thing at some point, perhaps with previous code.
Anyway, fixed, thank you for looking.
Hope something useful comes from this for somebody.
Nick
I'm sure I did the same thing at some point, perhaps with previous code.
Anyway, fixed, thank you for looking.
Hope something useful comes from this for somebody.
Nick
Thanks Fredrik!!🙂
Max
Max
hello,
got the same error-message with J1.6.
found out following (with standard-upload-path):
the folder for the upload-files will be created by the form if this not exists. inside the created folder is no the html-file as in the parent folder and so i get the error-message. if i copy the html-file from the parent folder into the created folder all works fine.
hope this helps and there will be a fix in future versions.
greetings
nick
got the same error-message with J1.6.
found out following (with standard-upload-path):
the folder for the upload-files will be created by the form if this not exists. inside the created folder is no the html-file as in the parent folder and so i get the error-message. if i copy the html-file from the parent folder into the created folder all works fine.
hope this helps and there will be a fix in future versions.
greetings
nick
Hi Nick,
Could you please try this on the new RC1.9 ? to upgrade just install it over the old one.
Regards,
Max
Could you please try this on the new RC1.9 ? to upgrade just install it over the old one.
Regards,
Max
This topic is locked and no more replies can be posted.