Re: DOFormBuilder :: ImageUpload

From: Date: Fri, 05 Nov 2004 17:39:53 +0000
Subject: Re: DOFormBuilder :: ImageUpload
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15360@lists.php.net to get a copy of this message
On Fri, 5 Nov 2004 18:35:55 +0100, Alexander Petri <alex.petri@gmx.de> wrote: > okay > the "$fb_" is my fault > if you wonder why i'm dont put the image_path into DB: > beacause i rename the file to $do->id.'.jpg' (the id entry of the inserted > data) > so i call parent::insert() before i upload the image with the id... Ok, this makes it all ok. In this case, you shouldn't have to save the filename. You will likely still want to unset the DO var before parent::insert() to make sure that DO doesn't try to insert a non-existant column. Since it's in table() it *will* try. > > the var "image_path" ought to be named in "image_file" or something like > that > > correct me if im wrong with this idea > > "Justin Patrin" <papercrane@gmail.com> schrieb im Newsbeitrag > news:432beae041105091618747478@mail.gmail.com... > > > > On Fri, 5 Nov 2004 15:58:02 +0100, Alexander Petri <alex.petri@gmx.de> > wrote: > > > I wanted to include a virtual imageupload Field in my DataObject > > > so i defined: > > > > > > class do_news extends DB_DataObject > > > { > > > .... > > > ###END_AUTOCODE > > > function insert($do = false){ > > > require_once 'DB/DataObject/Cast.php'; > > > $this->news_added = DB_DataObject_Cast::sql('NOW()'); > > > $this->news_updated = DB_DataObject_Cast::sql('NOW()'); > > > // > > > > Running this here is likely to try to insert Image_Path and it looks > > like it's not part of your DB. This is going to fail. You should unset > > $this->Image_Path before calling parent::insert(). > > > > unset($this->Image_Path); > > > > > parent::insert(); > > > if (is_uploaded_file($_FILES['Image_Path']["tmp_name"])) { > > > $this->Image_Path = $_FILES['Image_Path']["name"]; > > > > I assume you're using this field outside of the insert? If you're not > > using this field elsewhere, it's useless here. It won't get inserted > > into the DB and when you fetch this record later, it won't have an > > Image_Path entry. I would suggest actually putting the Image_Path > > column in your table and putting the name into it, as here, then do > > the insert after the move and such. > > > > > if > > > (move_uploaded_file($_FILES['Image_Path']["tmp_name"], > > > $this->id.".jpg") > > > && chmod($this->id.".jpg", 0644)) { > > > // echo "ok"; > > > > > > } > > > > parent::insert(); here instead of up there if you want to keep the > filename. > > > > > } > > > > > > function preGenerateForm(&$fb) { > > > $this->fb_preDefElements['news_text'] = > > > HTML_QuickForm::createElement('textarea', > > > > > > 'news_text','Newstext',array("cols"=>"35","rows"=>"6")); > > > $nr[0]="Normaler Bereich"; > > > $nr[1]="Privater Bereich"; > > > $this->fb_preDefElements['news_status'] = > > > HTML_QuickForm::createElement('select', 'news_status','News > Kategorie',$nr); > > > // File Upload > > > $this->fieldLabels = array ('Image_Path' => 'Choose image to > upload'); > > > > You forgot the fb_ here. $this->fb_fieldLabels. > > > > > $this->preDefElements['Image_Path'] = > > > HTML_QuickForm::createElement('file', 'Image_Path', 'File to > > > upload', > > > 'maxfilesize=5000000'); > > > > You also forgot the fb_ here. $this->fb_preDefElements. > > > > > > > > } > > > // Virtuelle Felder !!! > > > > > > function table() { > > > return array_merge(parent::table(), array( 'Image_Path' => > > > DB_DATAOBJECT_STR)); > > > } > > > > > > var > > > > > $fb_fieldsToRender=array('id','news_status','news_headline','news_subheadlin > > > e','news_text','Image_Path'); > > > > > > } > > > > > > but in my form the field appears as a normal text field > > > i guess the error is in the table() function > > > > > > thanks for help > > > > > > > > > > > -- > > paperCrane --Justin Patrin-- > -- paperCrane --Justin Patrin--

« previous php.pear.general (#15360) next »