• Fabrik4.5.3 for J!5.3.0 and J!4.2+is out

    You must update from Fabrik4.5.1 if you are running Joomla!5.3.0

    See Announcements

Solved Is it possible to copy fileupload image from one list to another?

I need to copy several elements from one list to another list. I'm doing this by using 2 php form plugins in List 1: one on "New" to create a record in List 2 and one on "Edit" to update the record in List 2 if the record in List 1 is updated. This works for all elements except one: a fileupload element for an image. I'm using the same code $mydb->setQuery ("INSERT INTO events VALUES(... for each element and they all copy correctly into the respective database columns except the fileupload element, which is empty.

I've Googled about MySQL escape characters but can't find a definitive answer on whether the leading "/" is causing a problem and what to do about it.

I've tried using the Upsert form plugin but this creates a new record in List 2 when the List 1 record is updated. Also, while the Upsert plugin correctly copies the fileupload element file path into the database column for List 2, it displays in the list as the image icon and the file path, as if the image couldn't be found. Could this be because the file paths are different for the two lists?

(I've also tried using a list join but there are elements in List 2 which don't exist in List 1 and vice versa, so I couldn't get this to display correctly. There are other reasons too, related to custom links to details.)

Is there a way to copy the image from one folder to another using the php form plugin?
 
Last edited:
Is it a ajax fileupload (with max >1)?
In this case the fileupload element has its own repeat DB table and you must copy all entries with parent_id= your-row-id from table1_repeat_fileupl1-element to table2_repeat_fileupl2-element (with parent_id=your-new-row-id-on-table2)
 
Then I don't see why it shouldn't do.
Provided that your fileupload elements in both lists have the same settings (i.e. same folders for image, thumb settings , crop settings etc).
Could this be because the file paths are different for the two lists?
The folder path is stored with the image, so if you have different path settings you must change the path before inserting it into table2 and you must copy the image into the new folder.
If you have thumb and/or crop settings you must also copy these images and adapt pre- and suffix etc.
 
Thanks @troester. That all makes sense. I can probably change the path setting in the php plugin by using the str_replace function, but I'm having difficulty getting my head around copying the image. It's probably really obvious, but I can't work out how to do it? And can I put it in the same php plugin (using onAfterProcess) or do I need another php form plugin, perhaps using onBeforeStore?
Thank you! :confused:
 
Nope! I'm having difficulty with this.

First hurdle: how do I get to the thumbnail image? I've only got a placeholder for the fileupload?
I've written some code into the form php plugin to isolate the image name from the list1 path, then add the path for list 2 to the start of this. I know this works because the output from this bit of code is correct. But in the database the path for list2 doesn't show the image name, only the start of the path. I assume this is because I haven't added the thumbnail.

Second hurdle: The copy function causes an error: 0 "path cannot be empty"

Thanks for any pointers!
 
The thumbnail image is defined via your fileupload settings:
It's in the "Thumbnail directory" , has the filename of the uploaded file (without the "Fileupload directory" part )+ pre and/or suffix (if set).

But in the database the path for list2 doesn't show the image name, only the start of the path. I assume this is because I haven't added the thumbnail.
No, this is not related to the thumbnail.

What is your code?
 
Code:
$artwork = '{listname___elementname}';
$image_name = explode("/",$artwork);
$image = $image_name[4];
$event_image = "/images/Events/".$image;
copy($artwork,$event_image);

the file path in the first element is /images/folder/folder/image.jpg

This is then followed by the code to insert the elements from list1 into list2, which I know works (except for the element). For the image element, I'm using the $event_image variable above.
 
I originally had the third line of the code as $image = $image_name[3]; but this produced no result at all in the database. I created a calc element in list1 to test the code by echoing out the result and it showed the second "/folder/" bit so I changed it to [4] and it displayed the correct file path.
 
OK, my code is now:
Code:
$artwork = '{listname___elementname}'; //$artwork is the fileupload image
$image_name = pathinfo($artwork,PATHINFO_BASENAME);
$event_image = "/images/Events/".$image_name;

But var_dump shows me an empty string! Even var_dump on the variable $artwork shows me an empty string. Why is the placeholder not working for the fileupload element? It's working for other elements. I'm using onAfterProcess in the form php plugin so the image should have loaded, shouldn't it?
 
Thanks so much! That corrects the code above and creates the new file path for list2. It's correctly placed in the database for list2 as well.
However, the
Code:
copy($artwork,$event_image);
command which I've placed immediately after the above doesn't copy the image from the original directory to the new one. :eek:
 
Any error?
You may have to provide full path names like JPATH_SITE . "/..." or COM_FABRIK_FRONTEND . "... or similar.

(I never know which one is which).
 

Members online

No members online now.
Back
Top