Re: DOFormBuilder :: ImageUpload
| From: | Justin Patrin | Date: | Fri, 05 Nov 2004 17:16:07 +0000 |
| Subject: | Re: DOFormBuilder :: ImageUpload | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15357@lists.php.net to get a copy of this message | ||
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--