Multi files upload doesn't work with iPad & iPhone

aleorco 28 Aug, 2013
Hi Bob, I've created a form with multi files upload widget. It works fine with Firefox, IE, Chrome: I choose n files with the same extension (e.g. .jpg) and the form sends an email with the n files attached.

It doesn't work with iPad & iPhone: if I choose more than one file, IOS assigned the same name to the files (e.g. 20130828094611_image.jpg) and so that files are uploaded in the folder with the same name, by overwriting them and only one is sent by email.

I've tried to drag a Custom Code action into the On Submit event of my form and added the code (as suggested in the forum http://www.chronoengine.com/faqs/3739-multiple-file-uploads-from-an-ipadiphone-dont-work-.html), but it doesn't work.
It doesn't rename the files with suffix _1, _2, ...
A question: should I rename the "$_FILES" array in the code with my own "file_upload" ?

Here's the screenshot of the position of the Custom Code action and the configuration:

Multi files upload doesn't work with iPad & iPhone image 1

Configuration of the Custom Code action:
Multi files upload doesn't work with iPad & iPhone image 2

Here's the link to the form:

http://www.orcoweb.it/psico/index.php?option=com_chronoforms&chronoform=richiesta_scheda_upload_file-Copy

P.S.1: I have Joomla 3.1.5 and the last version of Chronoforms installed (Chronoforms_V4.0.1_J3 & Plugin_Chronoforms_J3.0_V4_RC3.5.3).

P.S.2: all fields in the form are required. Fields named "CAP" require a 5 digit number.

Thanks for your help.

Alessandro
GreyHead 28 Aug, 2013
Hi Alessandro,

As far as I recall this worked OK when we wrote the code. I'd suggest that you add a line or two at the end to dump the $_FILES array and see what is happening.
<?php
echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>


Bob
aleorco 28 Aug, 2013
Hi, I added the code at the end of the Custom code action on Submit event:

<?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++;
}
?>
<?php
echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>
GreyHead 28 Aug, 2013
Hi aleorco,

And do you now see the $_FILES array when you submit the form? If so, what is in it?

Bob
aleorco 28 Aug, 2013
After submitting form (Debug mode ON) on my iPad:

Data Array:
Array
(
    [option] => com_chronoforms
    [chronoform] => richiesta_scheda_upload_file-Copy
    [event] => submit
    [nome] => Test
    [cognome] => Test
    [comune_nascita] => Test
    [data_nascita] => 17-12-1988
    [comune_residenza] => Test
    [cap] => 55556
    [indirizzo] => Test, 22
    [email] => my_email@libero.it
    [chk_iscrizione_ordine] => 1
    [indirizzo_invio] => test
    [cap_invio] => 56677
    [citta_invio] => test
    [provincia_invio] => test
    [multi_upload_limit_file_upload] => 2
    [chrono_verification] => NGy29
    [input_invia] => Invia dati
    [e40eded1f846a27129afbf434bc1e1e7] => 1
    [file_upload] => 20130828112730_image.jpg,20130828112730_image.jpg
    [_PLUGINS_] => 20130828112730_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,97292,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,20130828112730_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,74537,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg
    [chronoform_data] => Array
        (
            [cf_uid] => 271052777d4fe1330cd524d64d3620b0
            [cf_created] => 2013-08-28 11:27:31
            [cf_created_by] => 0
            [cf_ipaddress] => 151.95.61.255
            [cf_user_id] => 0
            [option] => com_chronoforms
            [chronoform] => richiesta_scheda_upload_file-Copy
            [event] => submit
            [nome] => Test
            [cognome] => Test
            [comune_nascita] => Test
            [data_nascita] => 17-12-1988
            [comune_residenza] => Test
            [cap] => 55556
            [indirizzo] => Test
            [email] => my_email@libero.it
            [chk_iscrizione_ordine] => 1
            [indirizzo_invio] => Test
            [cap_invio] => 56677
            [citta_invio] => Test
            [provincia_invio] => Test
            [multi_upload_limit_file_upload] => 2
            [chrono_verification] => NGy29
            [input_invia] => Invia dati
            [e40eded1f846a27129afbf434bc1e1e7] => 1
            [file_upload] => 20130828112730_image.jpg,20130828112730_image.jpg
            [_PLUGINS_] => 20130828112730_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,97292,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,20130828112730_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg,74537,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg
            [cf_id] => 45
        )

    [chronoform_data_cf_id] => 45
)


Validation Errors:
Array
(
)


Grazie. La tua richiesta è stata inviata correttamente.

Debug Data
Core Captcha
Passed the core captcha check!
Upload routine started for file upload by : file_upload
/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg has been uploaded successfully.
Upload routine started for file upload by : file_upload
/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg has been uploaded successfully.
email
10
Result
An email has been SENT successfully from (My account)my_test_email@mydomain.it to [email]info@mydomain.it[/email],my_email@libero.it
Body

Invio richiesta scheda di votazione


Attachments
array ( 0 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg', 1 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg', )

redirect_user
Error: No Redirect URL found

Powered By ChronoForms - ChronoEngine.com
Home
aleorco 28 Aug, 2013
Hi Bob, as you can see, iPhone and iPad named the 2 images with the same name "image":

array ( 0 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg', 1 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130828112730_image.jpg', )


and one image is overwritten.
GreyHead 28 Aug, 2013
Hi aleorco ,

So the code you added isn't doing anything. Do you have it running *before* the upload files action?

Bob
aleorco 28 Aug, 2013
Hi Bob, see the image on the first post: the Custom code action (with the code) is just below On submit and before the upload files action.

The numbers in red close to the action, indicate the order of execution of actions? How can I change it?

P.S.: Now I re-opened the Events tab and I see that the Custom code action was disappeared...
Do you have an idea why? Perhaps when I switch the Form Wizard Mode from Advanced to Easy?

Thanks!

Alessandro
GreyHead 28 Aug, 2013
Hi Alessandro,

The numbers are the order in which the actions were added, they are 'action id's and have nothing to so with the order of execution. That is set by the order within the event.

It sounds as though you need to re-add the Custom Code and see if it will save this time.

Bob
aleorco 28 Aug, 2013
Hi Bob, I re-drag Custom Code action into the On Submit event of my form (the Custom Code is the first action) and added the code, saved, but when I compile & submit the form, it seems that, as before, the Custom code action was by-passed.

Alessandro
GreyHead 01 Sep, 2013
Hi Alessandro,

Is the Code being saved in the Form Wizard now? What code exactly have you used? What does the Debugger output show?

Bob
aleorco 03 Sep, 2013
Hi Bob, if you want I can send you in PM the backup of the form, so you can see.

Alessandro
GreyHead 10 Sep, 2013
Hi Alessandro,

If you won't or can't answer my questions please don't expect me to take time looking at your forms :-(

Is the Code being saved in the Form Wizard now? What code exactly have you used? What does the Debugger output show?



Bob
aleorco 10 Sep, 2013
Sorry Bob, here's the answers:

The code is being saved in the Form Wizard (Custom Code - For iPad & iPhone (8)) before the UPLOAD event:

Multi files upload doesn't work with iPad & iPhone image 3

This is the code I added at the end of the Custom code action on Submit event:

Multi files upload doesn't work with iPad & iPhone image 4


<?php
    echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>

<?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++;
    }
    ?>
    


With iPad I have compiled the form and I have uploaded 2 images which have different names.

The Debugger output shows this:
P.S.: see the Array ( [0] => image.jpg [1] => image.jpg ): iPad assigns the same name to the 2 uploaded files.


$_FILES: Array ( [file_upload] => Array ( [name] => Array ( [0] => image.jpg [1] => image.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpwMrQUH [1] => /tmp/phpDru35S ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 559247 [1] => 275149 ) ) )


Data Array: 
Array
(
    [option] => com_chronoforms
    [chronoform] => richiesta_scheda_upload_file-Copy
    [event] => submit
    [nome] => Tutti
    [email] => pippo@libe.it
    [multi_upload_limit_file_upload] => 2
    [chrono_verification] => YGJEM
    [input_invia] => Invia dati
    [ac053f45858a6ccfce1d50133baf1ec4] => 1
    [file_upload] => 20130910185830_image.jpg,20130910185830_image.jpg
    [_PLUGINS_] => 20130910185830_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,1663052,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,20130910185830_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,473940,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg
    [chronoform_data] => Array
        (
            [cf_uid] => d9dff762a2f39b2ca23f5e8a6c136f55
            [cf_created] => 2013-09-10 18:58:30
            [cf_created_by] => 0
            [cf_ipaddress] => 151.95.62.35
            [cf_user_id] => 0
            [option] => com_chronoforms
            [chronoform] => richiesta_scheda_upload_file-Copy
            [event] => submit
            [nome] => Tutti
            [email] => pippo@libe.it
            [multi_upload_limit_file_upload] => 2
            [chrono_verification] => YGJEM
            [input_invia] => Invia dati
            [ac053f45858a6ccfce1d50133baf1ec4] => 1
            [file_upload] => 20130910185830_image.jpg,20130910185830_image.jpg
            [_PLUGINS_] => 20130910185830_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,1663052,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,20130910185830_image.jpg,image.jpg,/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg,473940,http://www.orcoweb.it/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg
            [cf_id] => 52
        )

    [chronoform_data_cf_id] => 52
)

Validation Errors: 
Array
(
)

Grazie.
La tua richiesta della scheda elettorale è stata inviata correttamente.


Debug Data
Core Captcha
Passed the core captcha check!
Upload routine started for file upload by : file_upload
/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg has been uploaded successfully.
Upload routine started for file upload by : file_upload
/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg has been uploaded successfully.

email

10

Result
An email has been SENT successfully from (Ordine Psicologi FVG)info@elezionipsicologifvg.it to info@web.it,pippo@libe.it

Body

Riceverai le schede relative alle votazioni.
Grazie.

Attachments
array ( 0 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg', 1 => '/home/mhd-01/www.orcoweb.it/htdocs/psico/uploads/richiesta_scheda_doc/20130910185830_image.jpg', )

redirect_user

Error: No Redirect URL found




P.S.: the form is ok in Windows with Firefox, IE, ecc.: the forms sends an email with all the attachments. For example, if I upload 2 photos, the email has 2 attachments.
If I use iPad or iPhone and upload 2 photos, the email has 1 attachments.

thanks.

Alessandro
aleorco 18 Sep, 2013
Hi Bob, do you need more information?
For me it's very important that the form run correctly on iPad/iPhone.

I'll thank you in advance for your help.

Alessandro
GreyHead 18 Sep, 2013
Hi Alessandro,

Everything looks OK - except that the name isn't changing and the values in _PLUGINS_ don't look quote right.

Please copy and paste this after the renaming code to see if it has worked.
<?php
    echo'<div>$_FILES: '.print_r($_FILES, true).'</div>';
?>
If not, then some debugging is required.

Bob

Bob
aleorco 18 Sep, 2013
Hi Bob, I've copied/pasted your debug code AFTER the renaming code to see if it works (Custom code - print debug after renaming):

Multi files upload doesn't work with iPad & iPhone image 5

As you see on the image, there are 3 Custom code:
1) Custom code - print debug before renaming code is the debug code
2) Custom code - for iPad&iPhone is the code for renaming files
3) Custom code - print debug after renaming code is the debug code

Then, with iPad, I compile the form, upload 2 files with the same name (geco.jpg) and I submit the form:

$_FILES: Array ( [file_upload] => Array ( [name] => Array ( [0] => image.jpg [1] => image.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpZBcmRt [1] => /tmp/phpGcYtuM ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 2615 [1] => 2615 ) ) )

$_FILES: Array ( [file_upload] => Array ( [name] => Array ( [0] => image.jpg [1] => image.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpZBcmRt [1] => /tmp/phpGcYtuM ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 2615 [1] => 2615 ) ) )

Data Array: ........ (the same as previous post)


It seems that the Custom code - for iPad&iPhone is not executed:

<?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++;
}
?>



Am I doing something wrong?
aleorco 23 Sep, 2013
Hi Bob, any idea on how to solve it?

Perhaps changing the code of the component to rename the file as:
RandomId_Filename.xxx instead of DateHour_Filename.xxx

What do you think?

Thanks.

Alessandro
aleorco 26 Sep, 2013
Hi Bob, following the idea of the previous post, I use the function php uniqid() to write a custom code that generates an unique identifier for each file and then renames the files before the upload and it works.
Now I can use the multi upload widget on iPhone/iPad.

thanks for you support.

Alessandro
GreyHead 28 Sep, 2013
Hi aleorco,

Great - good to see that you got a solution.

Just for other readers, I assume this is technically after the form is submitted but before the Upload Files action. It sounds similar to the example I posted except using a random string to rename the files instead of a serial number.

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