Use getFileInfo() to retrieve the original file infos your client sent.
This includes of course also the original filename.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Peter Smit" <[email protected]>
To: "Diego Potapczuk" <[email protected]>
Cc: "Thomas Weidner" <[email protected]>; <[email protected]>
Sent: Friday, January 01, 2010 12:51 PM
Subject: Re: [fw-general] Random filename when using Zend_Form_Element_File


If I use this filter, I seem to be not able to retrieve the originial
filename anymore. Is this correct, or is there a way to do that?

My code:
class Form_Upload extends Zend_Form
{
   public function init()
   {
       // Set the method for the display form to POST
       $this->setMethod('post');
       $this->setAttrib('accept-charset', 'UTF-8');
       $this->setAttrib('enctype', 'multipart/form-data');


       $this->addElement('file', 'file', array(
           'label'       => 'Files to upload:',
           'multiFile'   => 6,
           'validators'  => array(
               array('Count', false, array('min' =>1, 'max' => 100)),
               array('Size', false, array('max' => '500MB')),
           ),
           'filters'      => array(
               'Rename' => array('target' => APPLICATION_PATH.
'/../data/uploads/'),
            ),
       ));

       $this->addElement('submit', 'submit', array(
           'ignore'   => true,
           'label'    => 'Save',
       ));
   }
}


   public function indexAction()
   {
       if($this->getRequest()->isPost()) {
           $form = new Form_Upload();

           if (!$form->isValid($this->getRequest()->getPost()))
           {
               throw new Exception('Bad data:
'.print_r($form->getMessages(), true));
           }

           try {
               $form->file->receive();
           }
           catch (Zend_File_Transfer_Exception $e)
           {
               throw new Exception('Bad data: '.$e->getMessage());
           }
           print_r($form->file->getUnfilteredValue());
           print_r($form->file->getValue());
           print_r($form->file->getFileInfo());
           print_r($form->file->getFilename());

           echo "File uploaded";
       }



On Wed, Dec 30, 2009 at 4:15 PM, Diego Potapczuk <[email protected]>wrote:

For some reason it has no link in the filter section, but you can find
informations about it in the Zend_File section.

http://zendframework.com/manual/en/zend.file.html


::: Diego Potapczuk



On Wed, Dec 30, 2009 at 11:07 AM, Peter Smit <[email protected]> wrote:

Somehow I can't find the documentation of this filter. Can somebody give
me a hint where to find it?

Peter




On Wed, Dec 30, 2009 at 2:19 AM, Thomas Weidner <[email protected]>wrote:

Attach the "Rename" file filter to the element.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Peter Smit" <[email protected]>
To: <[email protected]>
Sent: Wednesday, December 30, 2009 12:32 AM
Subject: [fw-general] Random filename when using Zend_Form_Element_File



 Hey,

When I am using this in my form
      $this->addElement('file', 'file', array(
          'label'       => 'File to upload:',
          'destination' => APPLICATION_PATH.'/../data/uploads',
      'multiFile' => 3,
      ));

I have the problem that all files get their original name. This can
avoid
collisions as different people submit forms at the same time, or even
upload
two file with the same name in the same form.

I would like to have a kind of randomized filename instead with a method
to
retrieve the original filename. How can this be done, or how do others
solve
it?

Regards,

Peter Smit
---
+358 44 218 2700







Reply via email to