[CF5] Multiple upload iOS

ComSi , August 12 2014
C
ComSi

We're experiencing problems during multiple file upload in iOS because iOS gives the exact same name to each of the files in the multi-upload form, overwriting itself for every file. We have found a temporary fix though. (scroll down for a "quick" but very nasty fix which will make your code un-updatable).

Before you ask, the fix "Multiple file uploads from an iPad/iPhone don't work" from the FAQ doesn't work in CF5 for a number of reasons; $files is not used, files are already overwritten and many more.
https://www.chronoengine.com/faqs/53-cfv4/cfv4-file-uploads/3739-multiple-file-uploads-from-an-ipadiphone-dont-work-.html

What we've done to fix this in a future-proof kind of way (updating your plugin would otherwise overwrite our fix) is create two [custom code] actions in the form setup in Joomla. The first one before the "On submit" action, second one right after it.



Code before:
				<?php
// copy the temporary file to the temp dir with a hash of tmp_name
foreach( $_FILES as $key=>$value )
{
if( strlen( $value['tmp_name'] ) <= 0 )
continue;

$oFile = new \JFile();
$sTmpFile = sys_get_temp_dir() . '/' . md5( $value['tmp_name'] );
$oFile->copy( $value['tmp_name'], $sTmpFile );
}
?>


Code after:
				<?php
$oFile = new \JFile();
foreach( $form->files as $key=>$value )
{
// we copy the file again with a unique name so no files are overwritten
$sFilePath = pathinfo( $value['path'], PATHINFO_DIRNAME );
$sNewFilename = $sFilePath . '/' . date('YmdHis'). '_' . uniqid() . '_' . $value['original_name'];
$sTmpFile = sys_get_temp_dir() . '/' . md5( $_FILES[$key]['tmp_name'] );
$oFile->copy( $sTmpFile, $sNewFilename );

@unlink( $value['path'] );
@unlink( $sTmpFile );
$form->files[$key]['path'] = $sNewFilename;
$form->files[$key]['name'] = pathinfo( $sNewFilename, PATHINFO_BASENAME );
}
?>


==========
The fix that should be implemented by ChronoEngine is that $file_name should be actually unique, not just the current date. Even though the current code is second-specific, three uploaded files are all handled within this second which will create three filenames with the same string to prepend (date('YmdHis') becomes "201408131720" for all three).

Nasty fix for others experiencing this problem that don't care about future updates, change this:

/administrator/components/com_chronoforms5/chronoforms/actions/file_upload/file_upload.php
				//change
$file_name = date('YmdHis').'_'.$file_name;
//to
$file_name = uniqid(date('YmdHis').'_') . '_'.$file_name;
//which could create '201408131720_e3UaL83Lvy_filename.png'

Attachments
Screen Shot 2014-08-12 at 13.09.04.png
Screen Shot 2014-08-12 at 13.09.04.png
(39.32 KiB)
637 Downloads/Views
Powered by ChronoForums - ChronoEngine.com

ChronoForms Book

The ChronoForms Book, written for ChronoForms v3 contains 350 pages of invaluable ChronoForms How-tos hints and tips.

Note: many of the ideas can be used in ChronoForms v4 but the admin interface is very different and code examples may need to be modified.

SSL

Members Login

 

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by ChronoEngine.com