Hi Thomas

Thanks for your help and from the mailing list archive found that $_FILES
can be used to pickup original filename and to preserve extension. now once
i have added my Element_File I am using following to generate the random
file names, which works fine without doing extra work.

$this->getElement('logo_file')->addValidator('Extension', false, 'jpg,png');

if(isset($_FILES['logo_file']))
   if(isset($_FILES['logo_file']['name'])){
       $ext = pathinfo($_FILES['logo_file']['name']);
       $ext = $ext['extension'];
       
$this->getElement('logo_file')->addFilter('Rename',APPLICATION_PATH.'/../public/images/employer/logos/'.md5(time().$_FILES['logo_file']['name']).'.'.$ext);
   }

I think i need to put this logic into a separate class so the same logic
remains consistent through the project.

Another question, for my project related static functions and classes that i
use throughout my project should I put them in Api folder?

Thanks again and looking forward for your comments?

--------------------------------------------------
From: "Thomas Weidner" <thomas.weid...@gmx.at>
Sent: Tuesday, July 21, 2009 8:22 AM
To: <fw-general@lists.zend.com>
Subject: Re: [fw-general] Zend_Form_Element_File and random files name

You don't need to extend the rename filter.

Just take a look at the mailing lists archive. This question was asked and
answered about 3-5 times in past and code was also provided.

Do you really think that we have build the filter in a way where also the
base class have to be extended ?

When you don't get the clue what getNewName does and why the parameters
are given in that way then you should not change the classes. Else you
will have massive other problems when you do this.

Hint:
Keep in mind how a upload is processed... upload -> validate -> filter ->
move... so why should the original name be provided when the related file
does not exist at this time ?

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

----- Original Message ----- From: "Muhammad Ali" <imjob....@live.com>
To: <pe...@peterwarnock.com>
Cc: <fw-general@lists.zend.com>
Sent: Tuesday, July 21, 2009 3:58 AM
Subject: Re: [fw-general] Zend_Form_Element_File and random files name


Hi Pete,

So far my findings are as follows

In Zend_File_Transfer_Adapter_Http line 163 contains following code

                   $filename = $rename->getNewName($content['tmp_name']);

as you can see only temp file name is sent to the filter, there is nothing
much I can do here based on the original filename sent by the user. For
what I want to implement I have to change both
Zend_File_Transfer_Adapter_Http and a custom filter.

I think I would upload the file and rename is directly from the code using
a filter or something within the controller.

Thanks anyway.


From: Peter Warnock
Sent: Tuesday, July 21, 2009 2:06 AM
To: Muhammad Ali
Subject: Re: [fw-general] Zend_Form_Element_File and random files name


I haven't done it, but I would think extending the bfilter class with a
custom implementation would do the trick. - pw


 On Jul 20, 2009 6:04 PM, "Muhammad Ali" <imjob....@live.com> wrote:


 Hi Pete,

 Thanks for that, but there is no option to ignore extension i.e. so that
extension are taken care of  as for now you I can set new file name to
time() but it don't seems to keep the extension. Or do i have to do my own
filter for this purpose?

 Thanks


 From: Peter Warnock
 Sent: Tuesday, July 21, 2009 12:38 AM
 To: Muhammad Ali
 Subject: Re: [fw-general] Zend_Form_Element_File and random files name
 Take a look at
http://framework.zend.com/manual/en/zend.file.transfer.filters.html#zend.file.trans...



Reply via email to