⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Issue with two file uploads



ricardomduarte
  • profile picture
  • Member

Posted 12 January 2016 - 00:14 AM

Hi,

 

I found the following issue and thought I might share if someone ever runs across the same:

I had two upload fields:

$crud->set_field_upload('image_url','images/species'); 
$crud->display_as('image_url','Image'); 
$crud->set_field_upload('sound_url','sounds/species'); 
$crud->display_as('sound_url','Sound'); 

when I uploaded the second file it would replace the first file input and not the second

Looking into the generated html I noticed they had the exact same id's.

I fixed it by changing the function where the id is calculated:

protected function get_upload_file_input($field_info, $value){
...
usleep(2000); //added to prevent same unique id's if both are rendered on the same millisecond
$unique = uniqid(); //according to php the randomness is based on the current millisecond

Of course a long term fix can use a better way of randomization other than adding delays to the code, but this is just to illustrate the problem :)

 

Hope this helps anyone!