Hello Sarjono,
Thanks (also to Ukanga'a) for your help. I just tracked this down to the following:
Your code works indeed and puts the file in the destination directory. But when I set an action, calling the following view Action in my controller
public function uploadAction()
{
$this->view->keywords = "keywords";
$this->view->description = "description";
$this->view->pageTitle = "title";
$this->view->fileName = $this->getViewScript();
}
The file is removed from the destination directory.
I removed the actual view/logic so just displaying the page (with a layout which displays a header and footer and includes some meta data) removes the uploaded file from my destination directory. I am quite puzzled as to the reason of this behaviour. Someone any idea?
Timmo
On 7 August 2010 01:57, Sarjono Mukti Aji <sarjono.mukti.aji@gmail.com> wrote:
according to your code, i try to rewrite it to something like this:$this->view->msg = 'upload error';
//form model
class forms_ImportForm extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$uploadFile = new Zend_Form_Element_File('extract');
$uploadFile->setLabel('File')
->setDestination(APPLICATION_PATH . '/../data');
$uploadFile->addValidator('Count', false, 1);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit');
$this->setAttrib('enctype', 'multipart/form-data');
$this->addElements(array($uploadFile, $submit));
}
}
// controller
public function fileAction()
{
$fileform = new forms_ImportForm();
$this->view->fileform = $fileform;
$req = $this->getRequest();
if($this->getRequest()->isPost())
{
if($fileform->isValid($req->getPost()))
{
if(!$fileform->extract->receive())
{
}
}
}
}
i try this code on Windows, and it works fine..
http://framework.zend.com/manual/en/zend.form.standardElements.html
Best Regards,
Sarjono Mukti Aji
On 7 August 2010 01:12, zensys <timmo.henseler@gmail.com> wrote:
> I try to upload a file to a directory using setDestination but the file ends
> op in /tmp, whatever I try. Here's my code: class forms_ImportForm extends
> Zend_Form { public function __construct($options = null) {
> parent::__construct($options); $this->setName('import'); $uploadFile = new
> Zend_Form_Element_File('extract'); $uploadFile->setLabel('File')
> ->setDestination(APPLICATION_PATH ."/../data"); $submit = new
> Zend_Form_Element_Submit('submit'); $submit->setLabel('Uploaden');
> $this->addElements(array($uploadFile, $submit)); } } The method is called
> because the label is displayed and if I mutilate the file location I get an
> error. Any suggestions greatly appreciated. Timmo
> ________________________________
> View this message in context: setDestination in Zend_Form_Element_File
> Sent from the Zend DB mailing list archive at Nabble.com.
>
没有评论:
发表评论