|
|||
|
Hey folks,
My form element works just fine, with one exception... I wrote a small function to rename a particular photo to what I want although, as soon as the form is generated it automatically assigns the value, this of course is not too big a deal but it's just causing me some frustration, and I think I've been staring at the problem for a little too long and just need some fresh eyes. So here is the form element itself : PHP Code:
PHP Code:
Problem remains that as soon as the form loads the $photo section is now "x_photo." No matter if the user adds a file the file name stays the same... Granted the images do show up due to fairly smart browsers, but still this is something I would like to see fixed properly and I'm just staring at code at this point that looks right... Last edited by Nitecon : 11-21-2008 at 10:01 PM. Reason: Fixed a quotation mark that distorted the php |
|
|||
|
Just a stupid question myself:
Do you really think that the file element is named "$this->file" ? By simply omitting source, the file element will use it's own name.
__________________
Greetings Thomas Weidner I18N Team Leader, Zend Framework http://www.thomasweidner.com |
|
|||
|
I do realize it will use it's own name, but there are 2 problems here.
1. The form automatically calls the fromRename() function on initialization not on submit... 2. I need to change the file name, and at the same time get the extension, since I am allowing 3 different extensions for upload. So... if userx for instance uploads Myname.jpg, I need to parse the entire file with extension, rename the file to 1_photo.jpg, while keeping the extension as is. That way when userY uploads APhoto.gif, I can still get the extension. The first part is easy. It's getting the actual extension. So the way I see it there can be 2 solutions to this problem... The first being to find a way to hook the actual file name "onchange" (as in when the user hits the browse button and the value changes to something that is NotEmpty) or by adding some sort of filter or validator or action to getExtension on the particular form field. Now here is the swing part of it, if the user does not decide to upload a picture, because of the fact that the formRename() runs on init, there will automatically be a value, so the form element will automatically upload an empty file, so there has to be a check instead of using NotEmpty, but rather something like NotEmpty && OnChange. If this doesn't make any sense try it out yourself, I have tried just about everything so far, but I just can't find a way to get the extension ![]() |
|
|||
|
For now what I did to get around this issue is to instead of rename the file, make a directory by $id and store files in there. Although it does exactly what I need, I would still like to find out still how to manipulate the rename function or at least how to stop filters/validations from happening until the form actually submits.
|
|
|||
|
This is not really a issue of ZF but a handling problem of yourself.
When you want to add the filter after the file has been received you must do it in this order. When adding the filter before the file has been received, like you did it at initiation of the form, it is impossible for the filter to know the real uploaded name as you fixed source with the filename. You will have to: * Check if the file was uploaded * Check if the file is valid * Add the filter * Receive the file Simply do not receive the file element when no file was given ![]()
__________________
Greetings Thomas Weidner I18N Team Leader, Zend Framework http://www.thomasweidner.com |
![]() |
| Thread Tools | |
| Display Modes | |
|
|