⚠ 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

File upload uniqueid not unique



doritos

doritos
  • profile picture
  • Member

Posted 27 August 2013 - 21:53 PM

When adding or editing a form with 2 or more file upload elements only the first one is uploaded, no matter wich of all upload button you press.

 

This happen when the form generate a duplicate uniqueid for inputs and buttons that are involved in selecting and uploading a file.

 

The problem is that library Grocery_CRUD.php,v1.3,function get_upload_file_input,about line 2531, try to generate a uniqueid

$unique = uniqid()

 

But, according to this post: http://stackoverflow.com/a/4070285 it sometimes happen that 2 or more uniqueid are generated in same second(windows) or microsecond(unix), and this causes the failure with the upload file buttons.

 

In my case I just changed line $unique = uniqid() by $unique = rand(10,9999) and problems with file upload dissapear...

 

I suggest using something else than uniqid() to avoid this kind of problems...

 

 

 

 

 

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 28 August 2013 - 02:41 AM

Hello and welcome to the forums [member=doritos].

I will let know the core developer, [member=web-johnny] about this notice and solution.

Thanks again for this contribution.


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 August 2013 - 04:31 AM

Actually that's really an interesting thing to know :) . Thanks [member='doritos'] for the sharing. I will consider your thoughts and I will try to implement your code change in the future.

 

Thanks

Johnny


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 August 2013 - 04:45 AM

There you go. And the winner is mt_rand()  B)  https://github.com/scoumbourdis/grocery-crud/commit/8f3fc8e7d787bd155effedb9d925004bd8b07bb0