<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: File uploads with Zend_Form_Element_File</title>
	<atom:link href="http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/feed/" rel="self" type="application/rss+xml" />
	<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/</link>
	<description>Developing PHP software in the Real World, by Rob Allen</description>
	<lastBuildDate>Wed, 08 Feb 2012 14:36:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: BWorld</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-81249</link>
		<dc:creator>BWorld</dc:creator>
		<pubDate>Mon, 03 Oct 2011 09:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-81249</guid>
		<description>Hey Rob,

Nice and clear but I was wondering why you are calling populate() if the form isn&#039;t valid?

As far as I know the form is already populated with the values if you call isValid(), when Zend_Form::isValid() is calling Zend_Form_Element::isValid() in it&#039;s iteration automatically Zend_Form_Element::setValue() is called when the element is calling it&#039;s validators.</description>
		<content:encoded><![CDATA[<p>Hey Rob,</p>
<p>Nice and clear but I was wondering why you are calling populate() if the form isn't valid?</p>
<p>As far as I know the form is already populated with the values if you call isValid(), when Zend_Form::isValid() is calling Zend_Form_Element::isValid() in it's iteration automatically Zend_Form_Element::setValue() is called when the element is calling it's validators.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-74465</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 22 Aug 2011 18:04:36 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-74465</guid>
		<description>I&#039;ve solved this problem several days ago. So you may delete previous posts if you want.</description>
		<content:encoded><![CDATA[<p>I've solved this problem several days ago. So you may delete previous posts if you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-73325</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sun, 14 Aug 2011 18:12:51 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-73325</guid>
		<description>By the way, could you send me (or upload to somewhere) the example of uploading files using ajax(I use YUI library as in your book)? I would be very grateful. Thanks a lot.</description>
		<content:encoded><![CDATA[<p>By the way, could you send me (or upload to somewhere) the example of uploading files using ajax(I use YUI library as in your book)? I would be very grateful. Thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-73319</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sun, 14 Aug 2011 17:34:07 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-73319</guid>
		<description>I have a problem with uploading files using ajax. But if I use common submit button everything is ok. What should I do? It seems that this source code works not correctly(but if I delete the body of method and write $this-&gt;view-&gt;res = true I see correct result of ajax exchange):
public function indexAction() 
    {
        $this-&gt;view-&gt;headTitle(&#039;Home&#039;);
        $this-&gt;view-&gt;title = &#039;Zend_Form_Element_File Example&#039;;
        $this-&gt;view-&gt;bodyCopy = &quot;Please fill out this form.&quot;;

        $form = new forms_UploadForm();

        if ($this-&gt;_request-&gt;isPost()) {
            $formData = $this-&gt;_request-&gt;getPost();
            if ($form-&gt;isValid($formData)) {

                // success - do something with the uploaded file
                $uploadedData = $form-&gt;getValues();
                $fullFilePath = $form-&gt;file-&gt;getFileName();

                Zend_Debug::dump($uploadedData, &#039;$uploadedData&#039;);
                Zend_Debug::dump($fullFilePath, &#039;$fullFilePath&#039;);

                echo &quot;done&quot;;
                exit;

            } else {
                $form-&gt;populate($formData);
            }
        }

        $this-&gt;view-&gt;form = $form;

    }

Could you help me please?</description>
		<content:encoded><![CDATA[<p>I have a problem with uploading files using ajax. But if I use common submit button everything is ok. What should I do? It seems that this source code works not correctly(but if I delete the body of method and write $this-&gt;view-&gt;res = true I see correct result of ajax exchange):<br />
public function indexAction()<br />
    {<br />
        $this-&gt;view-&gt;headTitle('Home');<br />
        $this-&gt;view-&gt;title = 'Zend_Form_Element_File Example';<br />
        $this-&gt;view-&gt;bodyCopy = "Please fill out this form.";</p>
<p>        $form = new forms_UploadForm();</p>
<p>        if ($this-&gt;_request-&gt;isPost()) {<br />
            $formData = $this-&gt;_request-&gt;getPost();<br />
            if ($form-&gt;isValid($formData)) {</p>
<p>                // success - do something with the uploaded file<br />
                $uploadedData = $form-&gt;getValues();<br />
                $fullFilePath = $form-&gt;file-&gt;getFileName();</p>
<p>                Zend_Debug::dump($uploadedData, '$uploadedData');<br />
                Zend_Debug::dump($fullFilePath, '$fullFilePath');</p>
<p>                echo "done";<br />
                exit;</p>
<p>            } else {<br />
                $form-&gt;populate($formData);<br />
            }<br />
        }</p>
<p>        $this-&gt;view-&gt;form = $form;</p>
<p>    }</p>
<p>Could you help me please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hanny</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-69492</link>
		<dc:creator>Hanny</dc:creator>
		<pubDate>Mon, 18 Jul 2011 10:57:29 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-69492</guid>
		<description>

subform = $form;
        }
        else {
            //request coming from second subform
            $form_data = $request-&gt;getPost()
            $form = $SESSION[&#039;productController&#039;][&#039;subform&#039;];
            Zend_Debug::dump($_FILES);
            if ($form-&gt;isValid($form_data)) {
            // retrieve data from fist subform and save in variables
            foreach ($form_data as $key =&gt; $value) {
                //save post data  into database tables depending on second subform displayed
                if ($key == &#039;car&#039;) {
                    // I am always choosing same options from first sub form so that I always
                    // get this sub form for debugging purposes.
                    $title = $value[&#039;title&#039;];
                    ...
                    ...etc.
                    $uploaded_data = $form-&gt;getValues();
                    // $fullFilePath = form-&gt;pictures-&gt;getValues()
                }
                elseif (...) {
                    ...
                    ...
                elseif (...) {
                    ...
                    ...
                }                
                
            }
            $this-&gt;render(&#039;confirmation&#039;);
            exit;
        }
        else {
            $form-&gt;populate($form_data);
        }
    
    }
}



</description>
		<content:encoded><![CDATA[<p>subform = $form;<br />
        }<br />
        else {<br />
            //request coming from second subform<br />
            $form_data = $request-&gt;getPost()<br />
            $form = $SESSION['productController']['subform'];<br />
            Zend_Debug::dump($_FILES);<br />
            if ($form-&gt;isValid($form_data)) {<br />
            // retrieve data from fist subform and save in variables<br />
            foreach ($form_data as $key =&gt; $value) {<br />
                //save post data  into database tables depending on second subform displayed<br />
                if ($key == 'car') {<br />
                    // I am always choosing same options from first sub form so that I always<br />
                    // get this sub form for debugging purposes.<br />
                    $title = $value['title'];<br />
                    ...<br />
                    ...etc.<br />
                    $uploaded_data = $form-&gt;getValues();<br />
                    // $fullFilePath = form-&gt;pictures-&gt;getValues()<br />
                }<br />
                elseif (...) {<br />
                    ...<br />
                    ...<br />
                elseif (...) {<br />
                    ...<br />
                    ...<br />
                }                </p>
<p>            }<br />
            $this-&gt;render('confirmation');<br />
            exit;<br />
        }<br />
        else {<br />
            $form-&gt;populate($form_data);<br />
        }</p>
<p>    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hanny</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-69485</link>
		<dc:creator>Hanny</dc:creator>
		<pubDate>Mon, 18 Jul 2011 10:30:48 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-69485</guid>
		<description>Hello,

I am having problems validating a form with a file element in my application.

I am building an application that requires that I show 2 sub forms in a mult page format. The first sub form is always
the same and the second sub form shown will depend on the drop-down list of categories and subcategories selected in the
first sub form.

My form class contains this category sub form(the first sub form) and about 8 other sub forms (one of which will be
displayed depending on the information given in the first sub form). The reason is that the data I am collecting
is different for a lot of the categories. Some are however the same so the 8 sub forms include a more generic one
which is the parent class. This is also reflected in the database table structure. I have been able to get all
the logic for in my code for displaying the relevant sub form. Each second sub form includes a file element for
uploading pictures.

My controller class ProductController has the addAction that displays the initial subform through a function
I call getFirstSubform.
The post request from the first subform goes to a processAction which decides which sub form
to desplay as the second. The second and final subform also makes a trip to the same processAction of the
same controller. So the processAction has a logic to distinguish between these two POST request and to obtain the
appropriate post data. In the fist subform request, I save these post data as session variables for later
retrieval when saving to the database since these variables will be lost when making another browser request.
After running the function getNextSubForm() to return an instance of the relevant second subform. I have given an
explanatory code so you know what I am trying to do. During debugging I had the following observations.

1. The form validates correctly when I do not add the file element for the pictures. When added it fails validation.

2. When I include validators for the file elemement like addValidator(&#039;Count&#039;, false, array(&#039;min&#039; =&gt; 0, &#039;max&#039; =&gt; 6)),
   addValidator(&#039;Size&#039; false, &#039;4MB&#039;), addValidator(&#039;Extension&#039;, false, array(&#039;jpg&#039;, &#039;jpeg&#039;, &#039;png&#039;, &#039;gif&#039;)), I don&#039;t
   get any error message on form but it still fails validation and the form is repopulated.
   
3. When I do not include these validators, I get the error message: File &#039;pictures&#039; exceeds the defined ini size.
   I have made sure my second subform is set to enctype=&quot;multipart/form-data&quot;. I even explicitly set my first subform
   to this enctype during debugging just in case this was causing the error.
   In my PHP.ini file I have set post_max_size = 500M, upload_max_filesize = 500M, just to be sure this is not what
   is causing the error.
   
4. After retrieving $form form session in processAction, when I do $form-&gt;removeElement(&#039;pictures&#039;) just before
   the validation block, the validation works.
   
5.  When I upload a file. &#039;error&#039; is set to int(0). When I don&#039;t upload anything it&#039;s set to int(4). I don&#039;t find any
    in default temp folder C:\wamp\tmp after submiting the last form but will see the tempfile for a moment then it
    will quickly vanish. I can&#039;t see it in the folder I set if I include the method setDestination() on the file
    element.
    
    array
      &#039;pictures&#039; =&gt;
         array
            &#039;name&#039; =&gt; string &#039;this.jpg&#039;
            &#039;type&#039; =&gt; string &#039;image/jpeg&#039;
            &#039;tmp_name =&gt; &#039;C:\wamp\tmp\php93D.tmp&#039;
            &#039;error&#039; =&gt; int 0
            &#039;size&#039; =&gt; int 178993
   
Note: I am NOT using ajax, jQuery, or javascript on this subform at the moment. Only using Zend_Form_whatever.
I am using Zend Framework 1.11.9. with WAMP
   
Can you please help. I have been scratching my head on this for days.

subform = $form;
        }
        else {
            //request coming from second subform
            $form_data = $request-&gt;getPost()
            $form = $SESSION[&#039;productController&#039;][&#039;subform&#039;];
            Zend_Debug::dump($_FILES);
            if ($form-&gt;isValid($form_data)) {
            // retrieve data from fist subform and save in variables
            foreach ($form_data as $key =&gt; $value) {
                //save post data  into database tables depending on second subform displayed
                if ($key == &#039;car&#039;) {
                    // I am always choosing same options from first sub form so that I always
                    // get this sub form for debugging purposes.
                    $title = $value[&#039;title&#039;];
                    ...
                    ...etc.
                    $uploaded_data = $form-&gt;getValues();
                    // $fullFilePath = form-&gt;pictures-&gt;getValues()
                }
                elseif (...) {
                    ...
                    ...
                elseif (...) {
                    ...
                    ...
                }                
                
            }
            $this-&gt;render(&#039;confirmation&#039;);
            exit;
        }
        else {
            $form-&gt;populate($form_data);
        }
    
    }
}</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I am having problems validating a form with a file element in my application.</p>
<p>I am building an application that requires that I show 2 sub forms in a mult page format. The first sub form is always<br />
the same and the second sub form shown will depend on the drop-down list of categories and subcategories selected in the<br />
first sub form.</p>
<p>My form class contains this category sub form(the first sub form) and about 8 other sub forms (one of which will be<br />
displayed depending on the information given in the first sub form). The reason is that the data I am collecting<br />
is different for a lot of the categories. Some are however the same so the 8 sub forms include a more generic one<br />
which is the parent class. This is also reflected in the database table structure. I have been able to get all<br />
the logic for in my code for displaying the relevant sub form. Each second sub form includes a file element for<br />
uploading pictures.</p>
<p>My controller class ProductController has the addAction that displays the initial subform through a function<br />
I call getFirstSubform.<br />
The post request from the first subform goes to a processAction which decides which sub form<br />
to desplay as the second. The second and final subform also makes a trip to the same processAction of the<br />
same controller. So the processAction has a logic to distinguish between these two POST request and to obtain the<br />
appropriate post data. In the fist subform request, I save these post data as session variables for later<br />
retrieval when saving to the database since these variables will be lost when making another browser request.<br />
After running the function getNextSubForm() to return an instance of the relevant second subform. I have given an<br />
explanatory code so you know what I am trying to do. During debugging I had the following observations.</p>
<p>1. The form validates correctly when I do not add the file element for the pictures. When added it fails validation.</p>
<p>2. When I include validators for the file elemement like addValidator('Count', false, array('min' =&gt; 0, 'max' =&gt; 6)),<br />
   addValidator('Size' false, '4MB'), addValidator('Extension', false, array('jpg', 'jpeg', 'png', 'gif')), I don't<br />
   get any error message on form but it still fails validation and the form is repopulated.</p>
<p>3. When I do not include these validators, I get the error message: File 'pictures' exceeds the defined ini size.<br />
   I have made sure my second subform is set to enctype="multipart/form-data". I even explicitly set my first subform<br />
   to this enctype during debugging just in case this was causing the error.<br />
   In my PHP.ini file I have set post_max_size = 500M, upload_max_filesize = 500M, just to be sure this is not what<br />
   is causing the error.</p>
<p>4. After retrieving $form form session in processAction, when I do $form-&gt;removeElement('pictures') just before<br />
   the validation block, the validation works.</p>
<p>5.  When I upload a file. 'error' is set to int(0). When I don't upload anything it's set to int(4). I don't find any<br />
    in default temp folder C:\wamp\tmp after submiting the last form but will see the tempfile for a moment then it<br />
    will quickly vanish. I can't see it in the folder I set if I include the method setDestination() on the file<br />
    element.</p>
<p>    array<br />
      'pictures' =&gt;<br />
         array<br />
            'name' =&gt; string 'this.jpg'<br />
            'type' =&gt; string 'image/jpeg'<br />
            'tmp_name =&gt; 'C:\wamp\tmp\php93D.tmp'<br />
            'error' =&gt; int 0<br />
            'size' =&gt; int 178993</p>
<p>Note: I am NOT using ajax, jQuery, or javascript on this subform at the moment. Only using Zend_Form_whatever.<br />
I am using Zend Framework 1.11.9. with WAMP</p>
<p>Can you please help. I have been scratching my head on this for days.</p>
<p>subform = $form;<br />
        }<br />
        else {<br />
            //request coming from second subform<br />
            $form_data = $request-&gt;getPost()<br />
            $form = $SESSION['productController']['subform'];<br />
            Zend_Debug::dump($_FILES);<br />
            if ($form-&gt;isValid($form_data)) {<br />
            // retrieve data from fist subform and save in variables<br />
            foreach ($form_data as $key =&gt; $value) {<br />
                //save post data  into database tables depending on second subform displayed<br />
                if ($key == 'car') {<br />
                    // I am always choosing same options from first sub form so that I always<br />
                    // get this sub form for debugging purposes.<br />
                    $title = $value['title'];<br />
                    ...<br />
                    ...etc.<br />
                    $uploaded_data = $form-&gt;getValues();<br />
                    // $fullFilePath = form-&gt;pictures-&gt;getValues()<br />
                }<br />
                elseif (...) {<br />
                    ...<br />
                    ...<br />
                elseif (...) {<br />
                    ...<br />
                    ...<br />
                }                </p>
<p>            }<br />
            $this-&gt;render('confirmation');<br />
            exit;<br />
        }<br />
        else {<br />
            $form-&gt;populate($form_data);<br />
        }</p>
<p>    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajkumar</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-49422</link>
		<dc:creator>Rajkumar</dc:creator>
		<pubDate>Wed, 05 Jan 2011 08:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-49422</guid>
		<description>Hi Rob, could you explain me how to set a custom message when user had not uploaded any file when setRequired(true).</description>
		<content:encoded><![CDATA[<p>Hi Rob, could you explain me how to set a custom message when user had not uploaded any file when setRequired(true).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniel</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-31975</link>
		<dc:creator>daniel</dc:creator>
		<pubDate>Mon, 15 Mar 2010 21:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-31975</guid>
		<description>Why still Zend_form_element_file has wrong name when is nested in subform? It is because Multi-Page forms are not officially supported in Zend_Form? 

This problem was closed, please take a look
http://framework.zend.com/issues/browse/ZF-5835

Please Thomas help me.</description>
		<content:encoded><![CDATA[<p>Why still Zend_form_element_file has wrong name when is nested in subform? It is because Multi-Page forms are not officially supported in Zend_Form? </p>
<p>This problem was closed, please take a look<br />
<a href="http://framework.zend.com/issues/browse/ZF-5835" rel="nofollow">http://framework.zend.com/issues/browse/ZF-5835</a></p>
<p>Please Thomas help me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flavio</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-31752</link>
		<dc:creator>Flavio</dc:creator>
		<pubDate>Tue, 09 Mar 2010 18:49:02 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-31752</guid>
		<description>I used Zend_Form_Element_File to upload a file to webserver through a Zend_form class. How could I use the same class to download the file uploaded previously? I would appreciate any help.
Thank you,
Flávio.</description>
		<content:encoded><![CDATA[<p>I used Zend_Form_Element_File to upload a file to webserver through a Zend_form class. How could I use the same class to download the file uploaded previously? I would appreciate any help.<br />
Thank you,<br />
Flávio.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach</title>
		<link>http://akrabat.com/zend-framework/file-uploads-with-zend_form_element_file/#comment-24136</link>
		<dc:creator>Zach</dc:creator>
		<pubDate>Mon, 16 Feb 2009 16:36:18 +0000</pubDate>
		<guid isPermaLink="false">http://akrabat.com/?p=318#comment-24136</guid>
		<description>Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

