hschillig Posted February 20, 2014 Share Posted February 20, 2014 When I did a var_dump on $input[$file], it spits out this: array (size=1) 0 => object(Symfony\Component\HttpFoundation\File\UploadedFile)[9] private 'test' => boolean false private 'originalName' => string 'roi484-salesflyer-cf.pdf' (length=24) private 'mimeType' => string 'application/pdf' (length=15) private 'size' => int 286211 private 'error' => int 0 But this is erroring out: for($i = 0; $i < count($input[$file]); $i++) It's saying: illegal offset type $file just holds 'sheet_file', the name of the input field so I know what to reference. Any help here? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/286355-illegal-offset-type/ Share on other sites More sharing options...
requinix Posted February 20, 2014 Share Posted February 20, 2014 What's the rest of the code? Might you be overwriting $input or $file inside the loop? Quote Link to comment https://forums.phpfreaks.com/topic/286355-illegal-offset-type/#findComment-1469758 Share on other sites More sharing options...
hschillig Posted February 20, 2014 Author Share Posted February 20, 2014 (edited) The entire code is this: public function insertMedia($productId, $type, $name, $description, $file, $input) { if( ! $this->validateMediaType($type) ) { MsgConsole::setError('That is an invalid media type!'); return false; } for($i = 0; $i < count($input[$file]); $i++) { // Assign variable for easier use $file = $input[$file][$i]; $media = new ProductMedia(); $media->product_id = $productId; $media->name = $input[$name][$i]; $media->description = $input[$description][$i]; $media->type = $this->getMediaTypeInt( $type ); // Generate a unique url and attached the user_id $fileName = uniqid($productId.'_') . '.' . $file->guessClientExtension(); $media->file_path = $fileName; if( ! $media->save() ) { if($media->errors()->has($file)) { MsgConsole::setError('Your file may have not generated a unique combination. Please try uploading again.'); return false; } MsgConsole::setError($media->errors()->first()); return false; } else { if( ! $this->uploadFile($file, $fileName) ) return false; } } return true; } It's erroring out on this line actually: $file = $input[$file][$i]; But when I do a var_dump on it, it shows this: object(Symfony\Component\HttpFoundation\File\UploadedFile)[9] private 'test' => boolean false private 'originalName' => string 'roi484-salesflyer-cf.pdf' (length=24) private 'mimeType' => string 'application/pdf' (length=15) private 'size' => int 286211 private 'error' => int 0 ANSWER:Ah, it's because I was overwriting $file which was passed as an argument... Edited February 20, 2014 by hschillig Quote Link to comment https://forums.phpfreaks.com/topic/286355-illegal-offset-type/#findComment-1469759 Share on other sites More sharing options...
requinix Posted February 20, 2014 Share Posted February 20, 2014 Ah, it's because I was overwriting $file which was passed as an argument...Yup. Pick another variable name and you're good to go. Quote Link to comment https://forums.phpfreaks.com/topic/286355-illegal-offset-type/#findComment-1469779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.