Forums

Image uploads - sometimes same image 4 times?

weiseren 20 Mar, 2013
Hello

We have a form where you have to upload four individual images, but sometimes it shows the same image four times instead of four images. Some users have reported this.

This is correct example:
Image 1
20130320093912_Firefox.jpg
Image 2
20130320093912_Screen Shot 2013-03-19 at 3.38.34 PM.png
Image 3
20130320093912_418971_285171051555919_875316114_n.jpg
Image 4
20130320093912_logo-mob.png

This is an error sample:
Image 1
20130319223741_image.jpg
Image 2
20130319223741_image.jpg
Image 3
20130319223741_image.jpg
Image 4
20130319223741_image.jpg

Any ideas what could be causing this?
GreyHead 20 Mar, 2013
Hi weiseren,

I've not seen this before. If you can recreate the problem please drag a Debugger action into the On Submit event, then submit the form and post the results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab.

Bob
weiseren 21 Mar, 2013
I finally found the error.

Its when using an ipad to submit the form with images.

See debug attached.

BR
Kasper
GreyHead 22 Mar, 2013
Hi Kasper,

Well found. I don't' know much about the workings of iPads but it looks as though in the $_FILES array all four of the images have the same name: image.jpg This might explain why the problem occurs.

Without going to dig in the code my guess is that ChronoForms uses the value of the name parameter to rename the files and as it is the same in each case the later files over-write the earlier ones.

Bob
weiseren 02 Apr, 2013
Hello Bob,

It was 4 different images I tried to upload with the iPad so it must take image as the same filename.

I have ensure that all name attributes are different.

Would there be some fix which could ensure it writes different filenames - or is this a software/device issue with the iPad?

BR
Kasper
GreyHead 02 Apr, 2013
Hi Kasper,

I suspect that it is an 'iPad feature' - but I know nothing about their inner workings or how to debug them :-(

It should be possible to add a check in a Custom Code action to change the file names if they are the same. I'll see if I can put something together.

Bob
weiseren 02 Apr, 2013
Yes - I also just tested - if you send an email with a photo attachment, then no matter the image, it will always use the same filename when sending single files.

BR
Kasper
GreyHead 02 Apr, 2013
Hi Kasper,

Please try this code in a Custom Code action before the Upload Files action. It checks the $_FILES array and if more than one entry has the same name it adds a '_x' into the file name so your three image.jpg files become image.jpg, image_1.jpg and image_2.jpg.
<?php
if ( count( $_FILES ) <= 1 ) {
  return false;
}
$i = 1;
$temp = array();
jimport( 'joomla.filesystem.file' );
foreach ( $_FILES as $k => $v ) {
  if ( $i != 1 ) {
    if ( in_array( $v['name'], $temp ) ) {
      $ext  = JFile::getExt($v['name']);
      $name = JFile::stripExt($v['name']);
      $name = "{$name}_{$i}.{$ext}";
      $_FILES[$k]['name'] = $name;
    }
  }
  $temp[] = $_FILES[$k]['name'];
  $i++;
}
?>

Seems to work OK on my iPad. My test form is here for the moment.

Bob

PS I've added this to a new faq.
weiseren 02 Apr, 2013
I am using chronoforms for j1.5 - so I have some issues still, might be doing something simple wrong...

In the form management form code tab > On Submit code - before sending email, i pasted the code, but does not do anything.

Please see my attached screenshots - I am not sure which combinations should be used.

BR
Kasper
GreyHead 02 Apr, 2013
Hi Kasper,

Sorry, I hadn't noticed that you were using ChronoForms v3. The code would be similar. I'll they and check in the morning, not sure if I still have a test site with CFv3 on it.

Bob
weiseren 03 Apr, 2013
AH ok thanks a lot!

Happy to see that it was an issue that might help others too! Great.
GreyHead 03 Apr, 2013
Hi Kasper,

It looks as though this isn't going to work with ChronoForms v3 :-( The code I wrote still works correctly but the On Submit Before Email box is run after the File Upload is complete so it had no effect.

I'm afraid that I don't have any other suggestions: it's either hack the ChronoForms core code or upgrade to CFv4.

Bob
weiseren 03 Apr, 2013
How will my old forms cope with the upgrade to V4?

kw
GreyHead 04 Apr, 2013
Hi Kasper,

Possibly with difficulty as there is no automatic upgrade :-( I generally advise deferring it until you are ready to go to Joomla! 2.5-3.0

There's a FAQ with some more information.

Bob
This topic is locked and no more replies can be posted.