Khurram Ali
Khurram Ali

Reputation: 835

File Upload in Zend

i m using zend form & create its elements using the code below.

// To create text box.
$txt = $this->CreateElement('text', 'txtName');
$txt = $this->setLabel('First Name');
$elements[] = $element;

it works fine & it is posted firm form as well. But when i used the same technique to show a browse button, like.

// To Create Browse Button.
$img = $this->CreateElement('file', 'imageId');
$img = $this->setLabel('Upload Image');

$elements[] = $element;

it does not work.

Upvotes: 1

Views: 919

Answers (2)

Goran Jurić
Goran Jurić

Reputation: 1839

I guess this is a typo in your example and that you are actually using

$elements[] = $txt;
$elements[] = $img;

When you are using file elements you must not disable default decorators could it be that this is your problem?

Does it work if you are creating the file element like this:

$img = new Zend_Form_Element_File('imageId');
$img->setLabel('Upload Image');
$form->addElement($img);

Upvotes: 1

RageZ
RageZ

Reputation: 27323

you should consult the manual for Zend_Form_Element_File.

I am not sure but it would make sense if the destination option would be a requirement.

$element->setLabel('Upload an image:')
        ->setDestination('/var/www/upload');

also you have to make sure the webserver have enough permission to write the file.

Upvotes: 0

Related Questions