Monday, February 6, 2012

Re: strange image upload editing behavior

Right, sorry about that, that was actually a rename here for that
post. I'm using this model for several things that are to appear in a
banner that flips through some images and some flot output (http://
code.google.com/p/flot/) that is converted from csv files from several
different data sources. So the actual model is full of code that
converts the csv format to what flot expects. The conversions work
when first uploaded and I get correct flot output, but these csv files
experience the same behavior - a file called winter_inventory_2007.csv
will be shortened to "w".

I figured that images were something people worked with pretty often,
and the other code is only called when the case statement sees a
different "type" for the model, so I just posted those parts related
to the images so people wouldn't have too much code to ignore.

If it matters, the original name was "Rolledelement". I didn't think
that was too indicative of it being an image, but the name makes more
sense when there are multiple things which all need to be rolled
through in a banner.


Also, forgot to include: Cakephp 2.0.5.

On Feb 6, 2:19 pm, Tilen Majerle <tilen.maje...@gmail.com> wrote:
> hmm...model names are CamelCased, right ?
> so Imagelink will be better :)
> --
> Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> 2012/2/6 Dave D <its.dave.daw...@gmail.com>
>
> > Hi everybody, I'm working on creating an image upload section for my
> > site, and creating the images seems to work fine.  The uploaded image
> > information is saved correctly, the image is moved to the correct
> > folder and it looks like I can call the image from other parts of the
> > site just fine.
>
> > My problem comes up when I'm trying to edit the image.  When I upload
> > a new file, it appears that it only takes the first letter as the name
> > for the file.  For example, if I create an image on my site for the
> > google logo called "google.png", it will upload fine, but if
> > afterwards I try to upload a different file named "google.png" it will
> > call it just "g". or if I try to upload a file called "backup.png" it
> > will take the name as just "b".
>
> > It's not too big a problem since I can just delete the image and
> > create a new record for one, but it would be nice to be able to edit
> > the image and keep the rest of the record intact since I record some
> > other information along with what the image name is.
>
> > Here's the code from the add.ctp and edit.ctp files:
>
> > add ---
> > <?php
> >        echo $this->Form->create('imagelink', array('type'=>'file'));
> >        echo $this->Form->input('name');
> >        echo $this->Form->input('type');
> >        echo "Link"; echo $this->Form->text('link');
> >        echo $this->Form->input('place');
>
> >        echo "Info"; echo $this->Form->file('info');
>
> >        echo $this->Form->end('Save Element');
> > ?>
> > edit ---
> > <?php
> >        echo $this->Form->create('imagelink',array('action'=>'edit'));
> >        echo $this->Form->input('name');
> >        echo $this->Form->input('type');
> >        echo "Link"; echo $this->Form->text('link');
> >        echo $this->Form->input('place');
>
> >        echo "Info"; echo $this->Form->file('info');
>
> >        echo $this->Form->input('id',array('type'=>'hidden'));
> >        echo $this->Form->end('Save Modifications');
> > ?>
>
> > The controller has...
>
> >        public function add(){
> >                if ($this->request->is('post')){
> >                        if ($this->imagelink->save($this->request->data)){
> >                                $this->Session->setFlash('New element has
> > been saved.');
> >                                $this->redirect(array('action'=>'index'));
> >                        } else {
> >                                $this->Session ->setFlash('Unable to add
> > new element.');
> >                        }
> >                }
> >        }
>
> >        public function edit($id = null){
> >                $this->imagelink->id = $id;
> >                if ($this->request->is('get')) {
> >                        $this->request->data = $this->imagelink->read();
> >                } else {
> >                        if ($this->imagelink->save($this->request->data)) {
> >                                $this->Session->setFlash('Element has been
> > updated.');
> >                                $this->redirect(array('action' => 'index'));
> >                        } else {
> >                                $this->Session->setFlash('Unable to update
> > the
> > element.');
> >                        }
> >                }
> >        }
>
> > .. and the model has the beforeSave method:
>
> > move_uploaded_file($this->data['imagelink']['info']['tmp_name'],'img/'.
> > $this->data['imagelink']['info']['name']);
> >                        $this->data['imagelink']['info'] =
> > $this->data['imagelink']['info']
> > ['name'];
> >                        return true;
>
> > The database is only saving the image name instead of taking the whole
> > image as a blob, so before saving I wanted the image itself to be
> > moved to the img folder, and the name of the image to be stored in the
> > database.
>
> > If anybody can see anything that would cause cake to only take the
> > first letter of the new uploaded image when editing the record, or if
> > you suspect something, please let me know.
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: