Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Multiple Image Upload Single Field #207

Closed
spacebiscuit opened this issue Nov 30, 2016 · 8 comments
Closed

Multiple Image Upload Single Field #207

spacebiscuit opened this issue Nov 30, 2016 · 8 comments

Comments

@spacebiscuit
Copy link

Hi,

Does this plugin support multiple image uploads via a single field. I see that you have an example for multiple upload fields but not html5 multiple images on a single field.

TY.

@davidyell
Copy link
Owner

No it doesn't. I wasn't aware this was possible, sorry.

@spacebiscuit
Copy link
Author

Take a look at html5 - multiple attribute.

Thanks.

@davidyell
Copy link
Owner

On second thoughts, I'll reopen this as an enhancement.

@spacebiscuit
Copy link
Author

spacebiscuit commented Dec 3, 2016

I have been customising the plugin all day and although I can get it to work for multiple files on a single upload field, this then breaks the single file upload. My approach was to loop the array of objects that the multiple attribute produces. This works nicely but the issue is that there is nothing to loop for a single file upload, so I tried to move the single array into a 0 index to mimic the structure of the multiple file object but of course once I do this the object in not a valid instance of Cake\ORM\Entity so the new ProfferPath fails.

Seems to be a case of trying to fit a square peg into a round hole, perhaps it's just beyond me but I can't see an elegant solution other than a huge if statement and repeating masses of code to handle the two types of upload. I think I am beaten.

@davidyell
Copy link
Owner

My first thought is that the upload and processing of a single file works just fine. So the only thing which really needs to happen is checking if the submitted $_FILES array is a multiple or not. If it isn't, then the code can run as normal, and if it is a multiple, just call the existing code in a loop.

However I will qualify this by saying that I haven't looked at how the multiple file type input creates data in the request yet, so I am making an assumption here.

@spacebiscuit
Copy link
Author

spacebiscuit commented Dec 4, 2016

Agreed, I thought it would be a case of just looping the request data but consider the difference between the single and mulltiple file uploads:

Single file:

object(App\Model\Entity\Listing) {

	'title' => 'test',
	'vehicle_id' => (int) 1,
	'photo' => [
		'name' => 'quiz.jpg',
		'type' => 'image/jpeg',
		'tmp_name' => 'C:\Program Files\WAMP\tmp\php5CF.tmp',
		'error' => (int) 0,
		'size' => (int) 4094
	],

Mutliple:

object(App\Model\Entity\Listing) {

	'title' => 'test',
	'vehicle_id' => (int) 1,
	'photos' => [
		(int) 0 => object(App\Model\Entity\Photo) {

			'name' => 'podcast.png',
			'type' => 'image/png',
			'tmp_name' => 'C:\Program Files\WAMP\tmp\phpACFF.tmp',
			'error' => (int) 0,
			'size' => '48411',
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'name' => true,
				'type' => true,
				'tmp_name' => true,
				'error' => true,
				'size' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'Photos'
		
		},
		(int) 1 => object(App\Model\Entity\Photo) {

			'name' => 'quiz.jpg',
			'type' => 'image/jpeg',
			'tmp_name' => 'C:\Program Files\WAMP\tmp\phpAD00.tmp',
			'error' => (int) 0,
			'size' => '4094',
			'[new]' => true,
			'[accessible]' => [
				'*' => true
			],
			'[dirty]' => [
				'name' => true,
				'type' => true,
				'tmp_name' => true,
				'error' => true,
				'size' => true
			],
			'[original]' => [],
			'[virtual]' => [],
			'[errors]' => [],
			'[invalid]' => [],
			'[repository]' => 'Photos'
		
		}
	],

The multiple upload objects is an array of objects which I think is due to the patchEntity called in my controller. If I debug the request before this is called then I do see an array of arrays which would be ideal.

Any thoughts?

@spacebiscuit
Copy link
Author

I've managed to get this working, I will create the pull request tomorrow!

@davidyell
Copy link
Owner

Resolved, functionality has been developed and deployed now in release 0.8.1

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

2 participants