Buy Now
Sign in

FAQ search

Multiple file uploads from an iPad/iPhone don't work

Details
Published: Monday, 30 November -0001 00:00
It loosk as if the iPad and probably the iPhone gives the same file name to all file uploads, for images this is image.jpg. If you have more than one file upload in the same form then only one file will be uploaded because of this. Here is a workaround to avoid this problem. 
Drag a Custom Code action into the On Submit event of your form and add this code:
<?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++;
}
?>

The code checks the $_FILES array and if more than one entry has the same name it renames the duplicate by adding _n into the file name so that what were image.jpg, image.jpg, and image.jpg become image.jpg, image_1.jpg and image_2.jpg
You do not need this fix if you only have one File upload action in your form; or if you have several actions but they require different file types e.g. one accepts pdf-doc-docx and the other jpg-png