Iphone multi upload bug

cyberrocker 08 Sep, 2016
Hi Bob,
I have created a new form and found that multiple image uploads dont work with iphones. I have incorperated the below script but still doesnt work... any ideas??

I checked logs and it downloads 3 files, but all with the same name
<?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++;
}
?>


Regards

Ben
cyberrocker 08 Sep, 2016
There doesnt seam to be any error, but it is also sending the form twice. once with the form filled out, and once with the form empty
GreyHead 13 Sep, 2016
Hi Ben,

Sorry for the delay, I've been away travelling for a few days. The code you have there looks good - though it was written for CFv4 it looks as though it should work for CFv5 too.

Please drag a Debugger action into the On Submit event, then submit the form and, if you can, post the debug - including the 'dummy emails' results here.

Bob
cyberrocker 13 Sep, 2016
Hi Bob,
NO problems. I hope you enjoyed your holiday.

I ran the debugger when i was first informed of the problem (after including that code). And it was uploading all the files, but all of them were saved under the same file name.
GreyHead 14 Sep, 2016
Hi Ben,

Is the Custom Code before the Files Upload action? What exactly do you see as the file names in the Debugger?

Bob
cyberrocker 14 Sep, 2016
HI Bob,
The custom code is before the file uploads (at the top of that page). On the debugger, the name never changed. when used on iphone, it is (date)_image.jpeg
[attachment=0]admin code.jpg[/attachment]
I have tried to troubleshoot the script, but seams like, It does read the custom code, but doesn't act on anything past if (count($_FILES) <= 1) {
GreyHead 15 Sep, 2016
Hi cyberrocker,

Please take a Form Backup using the icon in the Forms Manager and post it here so I can take a closer look.

Bob
GreyHead 15 Sep, 2016
Hi Cyberrocker,

Thank you,

Please try this version.
<?php
$files = $_FILES['images']['name'];
$count = count($files);
if ( $count <= 1 ) {
  return false;
}
$i = 1;

$names = array();
jimport('joomla.filesystem.file');

foreach ( $files as $k => $v ) {
  // check for duplicate names
  if ( $i == 1 || !in_array( $v, $names) ) {
    $names[]  = $v;
    $i++;
    continue;
  }
  // duplicate found
  $ext        = JFile::getExt($v);
  $name       = JFile::stripExt($v);
  $name       = "{$name}_{$i}.{$ext}";
  $files[$k]  = $name;
  $names[]    = $name;
  $i++;
}
$_FILES['images']['name'] = $files;
?>
It appears that the $_FILES array structure is not the same as the old code was expecting.

I have tested this on my desktop using duplicated selections and it is fine. Please let me know if you have any problems with a iphone.

Bob
cyberrocker 16 Sep, 2016
Thats great, it works well.. Thanks very much for all your help🙂
This topic is locked and no more replies can be posted.