No, your assumption is wrong. :-)

When you say "Ignore when there is no file uploaded",
why should receive then say "Failure, there is no file uploaded" ?

The return value of receive does only return true when something has not worked. By saying "ignore it", you said "even if I know that it does not work, ignore that no file has been uploaded and return true in such a case".

getFileName on the other hand returns the set values for a file element.
When there is no file uploaded, for example before you post your form, it will return the path where the upload will be received.

For the file transfer adapter this is logical.
The adapter itself is built to support not only HTTP upload but also other protocols and directions. It could receive a complete directory and store it on another location.

When you are using the file element as you wrote, you should stick with getValue(), as it returns null when there is no file or no upload and the filename when there was a upload, but without path.

Regarding your filter problem:
The normal usage in such a case would be...
* validate form
* add personal filter
* receive the file

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

----- Original Message ----- From: "Edward Haber" <[EMAIL PROTECTED]>
To: "Thomas Weidner" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Wednesday, November 12, 2008 2:39 PM
Subject: Re: [fw-general] Zend_Form_Element_File - is this a BUG or expected?


Thanks for your help on this. It is much appreciated.

I think it's pretty reasonable to think the construct "if ($this-
>my_file->receive())" should return true only if the file is actually
*received.* What else would a person conceivably be receiving? Whether or not the upload is required or optional this shouldn't effect it. Further, getFileName() shouldn't return the destination file-path when there is no upload *because there is no file*. Makes no sense.

I had renamed manually because I need the product_id which I only have after gotten the last-insert-id from the save operation (my filenames are product_id.jpg). Is there a clever way to manage this from in the form that you know of? I would rather utilize the rename filter but I do not know the product-id until after validation.

I tried (as you kindly/smugly suggested) the "isUploaded" hint but it lead to an error:

if ($form->my_file->receive()) {
if ($form->my_file->isUploaded()) {
... stuff ...
}
}
Error: "Method isUploaded does not exist."

The way that worked for me was to check if getFileName() is a directory with is_dir(), a rather odd thing to have to do. However this worked.

Thanks again!


On Nov 12, 2008, at 2:30 AM, Thomas Weidner wrote:

To clearify this:
You are using trunk, but your code would not work.

As you wrote, you upload no file, and call receive().
Receive can sometimes return true, for example when you set the file element it to be optional in the form, or when you set the ignoreNoFile option in the adapter.

There are other ways to check this than relying on receive itself.

Also to note:
You rename manually and do not use the rename filter from Zend_File which means that YOU rename the file and not the component.
Simply calling receive is not enough as you have noted.
When you are doing implementations yourself you are also responsible of doing checks yourself.
In your case a simple check if the file has been uploaded or not. :-))

Hint: "isUploaded"

And as Matthew already noted:
When someone uses trunk he should also read the manual of trunk.
Online docs always refer to the latest stable release and not  trunk. ;-)

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

----- Original Message ----- From: "Edward Haber" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, November 12, 2008 3:28 AM
Subject: Re: [fw-general] Zend_Form_Element_File - is this a BUG or expected?


I'm working off svn of the current trunk.

On Nov 11, 2008, at 9:21 PM, Matthew Weier O'Phinney wrote:

-- Edward Haber <[EMAIL PROTECTED]> wrote
(on Tuesday, 11 November 2008, 08:24 PM -0500):
If no file is uploaded, receive() still returns true? Here's an example:

Please test against trunk. The component has undergone a lot of work in
the past two weeks, with basically daily check-ins.

Additionally, read the current docbook documentation from trunk as well.

if ($form->isValid($formData)) {
... do some stuff ...
... set $product_id to INT ...

// process form image
if ($form->product_image->receive()) {
rename($form->product_image->getFileName(), AP . "/media/products/
$product_id.jpg");
}
}

With the above code, if no file is uploaded my destination  directory
gets renamed. So, if there is no file, receive() is still returning true and getFileName() is equal to the destination directory and consequently
the whole directory gets renamed as 5.jpg (for example).

Is this expected or am I implementing incorrectly?! I've asked some dumb
questions on this list before. Hopefully this is another one.

BTW, as someone else just noted the docs must be updated! Let me know if
i can help. I know some HTML.
Thx!!


On Nov 11, 2008, at 4:55 PM, Simon Corless wrote:


A quick question to Thomas I suppose, how do I get the file name /
location
from a file uploaded using Zend_Form.

The docs contradict themselves...

In the code it uses:
$location = $form->foo->getFileName();

Then goes on to state in a note below:
"File values
Within HTTP a file element has no value. Therefor you will get no
output
when calling getValue()."

So I suppose it's a small bug in the docs, but ultimately I need  the
file
name so how do I get it?!

Thanks
Simon

-----
Simon

http://www.ajb007.co.uk/
--
View this message in context: http://www.nabble.com/Zend_Form_Element_File---getValue%28%29-in-1.7-tp20449098p20449098.html
Sent from the Zend Framework mailing list archive at Nabble.com.



--
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/


Reply via email to