Error on file upload

nicholashg 01 Apr, 2011
I'm getting this when I submit a form with a file attached:

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?
GreyHead 02 Apr, 2011
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.
			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
nicholashg 02 Apr, 2011
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
nicholashg 02 Apr, 2011
Sorry - the upload directory HAS been created, I didn't refresh my ftp.
N
nml375 02 Apr, 2011
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
GreyHead 02 Apr, 2011
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
nicholashg 02 Apr, 2011
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
nml375 02 Apr, 2011
Hi again,
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
nicholashg 02 Apr, 2011
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
GreyHead 04 Apr, 2011
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
GreyHead 04 Apr, 2011
Hi Nick,

Appears to work Ok now, I moved the file upload before the DB Save.

Bob
nicholashg 04 Apr, 2011
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
Max_admin 07 Apr, 2011
Thanks Fredrik!!🙂

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
NickDE 28 May, 2011
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
GreyHead 29 May, 2011
Ni Nick,

Please check this post to see if the fix there works for you.

There's also a modifed File Upload Action here.

Bob
Max_admin 31 May, 2011
Hi Nick,

Could you please try this on the new RC1.9 ? to upgrade just install it over the old one.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.