Re: File uploads - getting an undefined index.
Apologies for the late reply - I solved this, it was a really silly error on my part! I was accessing the array but not the specific field I needed. On Jun 21, 5:37 pm, brian wrote: > What does the controller code look like now? Specifically, where it > interacts with your ImageComponent. > > > > On Sun, Jun 21, 2009 at 11:46 AM, number9 wrote: > > > OK, so I have solved theundefinedindex problem - the view file was > > wrong, it should have been "Tip.image" instead of just image. However, > > I changed it to "Img.pic" so as not to clash with image. > > > I'm now getting the following error when trying to "add": > > > Notice (8): Array to string conversion [APP\controllers\components > > \image.php, line 50] > > Warning (2): strrpos() expects parameter 1 to be string, array given > > [APP\controllers\components\image.php, line 145] > > > I've done some searching, and I understand that the error means an > > array is being given as opposed to a string, but I didn't really come > > across a fix? Has anybody got any ideas? > > > Thanks in advance! > > > On Jun 20, 6:19 pm, number9 wrote: > >> I'm trying to add the ability to upload files on an existing add > >> method within a controller, but no matter which method I use to try > >> and upload files I get an "undefinedindex" error on the name of the > >> field within the view and I cannot understand why. > > >> I thought it may have been a problem with the components I was trying, > >> but after stripping back to a simple bit of code found here > >> (http://www.davidgolding.net/cakephp/using-the-file-functions-in-cakep...) > >> - I am still getting the error. > > >> Code looks like this: > > >> // Controller: > > >> if ($this->data['Tip']['image']) { > > >> $file = new > >> File($this->data['Tip']['image']); > >> $ext = $file->ext(); > > >> if ($ext != 'jpg' && $ext != 'jpeg' && > >> $ext != 'gif' && $ext != > >> 'png') { > >> $this->Session->setFlash('You may only > >> upload image files.'); > >> $this->render(); > >> } else { > >> $date = $this->data['Tip']['created']; > >> $filename = > >> $date['year'].'-'.$date['month'].'-'.$date['day'].'- > >> post-image.'.$ext; > > >> $data= $file->read(); > >> $file->close(); > > >> $file = new > >> File(WWW_ROOT.'/img/'.$filename,true); > >> $file->write($data); > >> $file->close(); > >> } > >> } > > >> // View file: > > >> create('Tip',array('type'=>'file')); ?> > >> > >> > >> >> echo $form->input('comment_count'); > >> echo $form->input('name'); > >> echo $form->input('slug'); > >> echo $form->input('description'); > >> echo $form->input('image',array('type'=>'file')); > >> echo $form->input('expires'); > >> echo $form->input('rating'); > >> echo $form->select('Tip.category_id', $cat_list, null, > >> array(), > >> true); > >> echo $form->input('site_id'); > >> echo $form->input('user_id'); > >> echo $form->input('Tag.name',array( > >> 'type' => 'text', > >> 'label' => __('Add Tags',true), > >> 'after' => __('Seperate each tag with a > >> comma. Eg: family, sports, icecream',true) > >> )); > >> ?> > >> > >> end('Submit');?> > > >> There is more in the controller file, but I thought I would include > >> just the relevant information for the time being. Is it possible that > >> something else in there is conflicting with the code? I tried also > >> adding ['tmp_name'] but no joy... > > >> Any insight would be appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: File uploads - getting an undefined index.
What does the controller code look like now? Specifically, where it interacts with your ImageComponent. On Sun, Jun 21, 2009 at 11:46 AM, number9 wrote: > > OK, so I have solved the undefined index problem - the view file was > wrong, it should have been "Tip.image" instead of just image. However, > I changed it to "Img.pic" so as not to clash with image. > > I'm now getting the following error when trying to "add": > > Notice (8): Array to string conversion [APP\controllers\components > \image.php, line 50] > Warning (2): strrpos() expects parameter 1 to be string, array given > [APP\controllers\components\image.php, line 145] > > I've done some searching, and I understand that the error means an > array is being given as opposed to a string, but I didn't really come > across a fix? Has anybody got any ideas? > > Thanks in advance! > > On Jun 20, 6:19 pm, number9 wrote: >> I'm trying to add the ability to upload files on an existing add >> method within a controller, but no matter which method I use to try >> and upload files I get an "undefined index" error on the name of the >> field within the view and I cannot understand why. >> >> I thought it may have been a problem with the components I was trying, >> but after stripping back to a simple bit of code found here >> (http://www.davidgolding.net/cakephp/using-the-file-functions-in-cakephp.html) >> - I am still getting the error. >> >> Code looks like this: >> >> // Controller: >> >> if ($this->data['Tip']['image']) { >> >> $file = new >> File($this->data['Tip']['image']); >> $ext = $file->ext(); >> >> if ($ext != 'jpg' && $ext != 'jpeg' && $ext >> != 'gif' && $ext != >> 'png') { >> $this->Session->setFlash('You may only >> upload image files.'); >> $this->render(); >> } else { >> $date = $this->data['Tip']['created']; >> $filename = >> $date['year'].'-'.$date['month'].'-'.$date['day'].'- >> post-image.'.$ext; >> >> $data = $file->read(); >> $file->close(); >> >> $file = new >> File(WWW_ROOT.'/img/'.$filename,true); >> $file->write($data); >> $file->close(); >> } >> } >> >> // View file: >> >> create('Tip',array('type'=>'file')); ?> >> >> >> > echo $form->input('comment_count'); >> echo $form->input('name'); >> echo $form->input('slug'); >> echo $form->input('description'); >> echo $form->input('image',array('type'=>'file')); >> echo $form->input('expires'); >> echo $form->input('rating'); >> echo $form->select('Tip.category_id', $cat_list, null, >> array(), >> true); >> echo $form->input('site_id'); >> echo $form->input('user_id'); >> echo $form->input('Tag.name',array( >> 'type' => 'text', >> 'label' => __('Add Tags',true), >> 'after' => __('Seperate each tag with a >> comma. Eg: family, sports, icecream',true) >> )); >> ?> >> >> end('Submit');?> >> >> There is more in the controller file, but I thought I would include >> just the relevant information for the time being. Is it possible that >> something else in there is conflicting with the code? I tried also >> adding ['tmp_name'] but no joy... >> >> Any insight would be appreciated. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: File uploads - getting an undefined index.
OK, so I have solved the undefined index problem - the view file was wrong, it should have been "Tip.image" instead of just image. However, I changed it to "Img.pic" so as not to clash with image. I'm now getting the following error when trying to "add": Notice (8): Array to string conversion [APP\controllers\components \image.php, line 50] Warning (2): strrpos() expects parameter 1 to be string, array given [APP\controllers\components\image.php, line 145] I've done some searching, and I understand that the error means an array is being given as opposed to a string, but I didn't really come across a fix? Has anybody got any ideas? Thanks in advance! On Jun 20, 6:19 pm, number9 wrote: > I'm trying to add the ability to upload files on an existing add > method within a controller, but no matter which method I use to try > and upload files I get an "undefined index" error on the name of the > field within the view and I cannot understand why. > > I thought it may have been a problem with the components I was trying, > but after stripping back to a simple bit of code found here > (http://www.davidgolding.net/cakephp/using-the-file-functions-in-cakephp.html) > - I am still getting the error. > > Code looks like this: > > // Controller: > > if ($this->data['Tip']['image']) { > > $file = new File($this->data['Tip']['image']); > $ext = $file->ext(); > > if ($ext != 'jpg' && $ext != 'jpeg' && $ext > != 'gif' && $ext != > 'png') { > $this->Session->setFlash('You may only upload > image files.'); > $this->render(); > } else { > $date = $this->data['Tip']['created']; > $filename = > $date['year'].'-'.$date['month'].'-'.$date['day'].'- > post-image.'.$ext; > > $data = $file->read(); > $file->close(); > > $file = new > File(WWW_ROOT.'/img/'.$filename,true); > $file->write($data); > $file->close(); > } > } > > // View file: > > create('Tip',array('type'=>'file')); ?> > > > echo $form->input('comment_count'); > echo $form->input('name'); > echo $form->input('slug'); > echo $form->input('description'); > echo $form->input('image',array('type'=>'file')); > echo $form->input('expires'); > echo $form->input('rating'); > echo $form->select('Tip.category_id', $cat_list, null, > array(), > true); > echo $form->input('site_id'); > echo $form->input('user_id'); > echo $form->input('Tag.name',array( > 'type' => 'text', > 'label' => __('Add Tags',true), > 'after' => __('Seperate each tag with a > comma. Eg: family, sports, icecream',true) > )); > ?> > > end('Submit');?> > > There is more in the controller file, but I thought I would include > just the relevant information for the time being. Is it possible that > something else in there is conflicting with the code? I tried also > adding ['tmp_name'] but no joy... > > Any insight would be appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
File uploads - getting an undefined index.
I'm trying to add the ability to upload files on an existing add method within a controller, but no matter which method I use to try and upload files I get an "undefined index" error on the name of the field within the view and I cannot understand why. I thought it may have been a problem with the components I was trying, but after stripping back to a simple bit of code found here (http:// www.davidgolding.net/cakephp/using-the-file-functions-in-cakephp.html) - I am still getting the error. Code looks like this: // Controller: if ($this->data['Tip']['image']) { $file = new File($this->data['Tip']['image']); $ext = $file->ext(); if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') { $this->Session->setFlash('You may only upload image files.'); $this->render(); } else { $date = $this->data['Tip']['created']; $filename = $date['year'].'-'.$date['month'].'-'.$date['day'].'- post-image.'.$ext; $data = $file->read(); $file->close(); $file = new File(WWW_ROOT.'/img/'.$filename,true); $file->write($data); $file->close(); } } // View file: create('Tip',array('type'=>'file')); ?> input('comment_count'); echo $form->input('name'); echo $form->input('slug'); echo $form->input('description'); echo $form->input('image',array('type'=>'file')); echo $form->input('expires'); echo $form->input('rating'); echo $form->select('Tip.category_id', $cat_list, null, array(), true); echo $form->input('site_id'); echo $form->input('user_id'); echo $form->input('Tag.name',array( 'type' => 'text', 'label' => __('Add Tags',true), 'after' => __('Seperate each tag with a comma. Eg: family, sports, icecream',true) )); ?> end('Submit');?> There is more in the controller file, but I thought I would include just the relevant information for the time being. Is it possible that something else in there is conflicting with the code? I tried also adding ['tmp_name'] but no joy... Any insight would be appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---