Zend_Form / Zend_File Upload to DB not working

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Form / Zend_File Upload to DB not working

maxarbos
Hello,

I am trying to use Zend_Form to upload a file and then store it in a DB.

Something doesnt seem to be working, and would like to know if there is a simple test using MVC structure to see if a file is being uploaded?

I have tried a few things, but nothing seems to show the actual file info trying to be uploaded.

Any tutorials would be greatly appreciated.

thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form / Zend_File Upload to DB not working

Thomas Weidner
Look at my blog.
There is an example for file uploads.
http://www.thomasweidner.com/flatpress/2008/11/01/file-transfer-hashing-and-other-news/

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

----- Original Message -----
From: "maxarbos" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, January 27, 2009 9:43 PM
Subject: [fw-general] Zend_Form / Zend_File Upload to DB not working


>
> Hello,
>
> I am trying to use Zend_Form to upload a file and then store it in a DB.
>
> Something doesnt seem to be working, and would like to know if there is a
> simple test using MVC structure to see if a file is being uploaded?
>
> I have tried a few things, but nothing seems to show the actual file info
> trying to be uploaded.
>
> Any tutorials would be greatly appreciated.
>
> thank you.
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form---Zend_File-Upload-to-DB-not-working-tp21693984p21693984.html
> Sent from the Zend Framework mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form / Zend_File Upload to DB not working

maxarbos
Thank you. I am now able to get the file to upload, but now stuck as to how to get it to display within ZF.

When I make the call to the code to show the image, I am just getting the characters of the source of the image and not the image itself. I used to do something like this when I was able to call a specific page that sent headers and such, but with ZF and Ajax calls, it doesnt seem to work the same.

Is there something I am missing/forgetting to get the image to display?

Thank you.


thomasW wrote
Look at my blog.
There is an example for file uploads.
http://www.thomasweidner.com/flatpress/2008/11/01/file-transfer-hashing-and-other-news/

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form / Zend_File Upload to DB not working

Michael Crumm
Make sure you are setting headers that match the type of image data being stored.
Here's a controller i've used in the past for displaying image data.  This particular example gets its data from a file on the filesystem, but the same would hold true for data from the database. 

One thing to note:
Watch your closing tags.  Worst case, make sure there is no trailing whitespace or newlines.  Best case, just omit the closing tag completely.  Additional whitespace can cause issues with the image data being rendered.

Hope this helps!

<?php
class ImageController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->ViewRenderer->setNoRender();
       
        $file = '/path/to/file';
       
        $info = getimagesize($file);
        $mimeType = $info['mime'];
       
        $size = filesize($file);
       
        $data = file_get_contents($file);
       
        $response = $this->getResponse();
        $response->setHeader('Content-Type', $mimeType, true);
        $response->setHeader('Content-Length', $size, true);
        $response->setBody($data);
        $response->sendResponse();
        die();           
    }
}


On Wed, Jan 28, 2009 at 9:13 AM, maxarbos <[hidden email]> wrote:

Thank you. I am now able to get the file to upload, but now stuck as to how
to get it to display within ZF.

When I make the call to the code to show the image, I am just getting the
characters of the source of the image and not the image itself. I used to do
something like this when I was able to call a specific page that sent
headers and such, but with ZF and Ajax calls, it doesnt seem to work the
same.

Is there something I am missing/forgetting to get the image to display?

Thank you.



thomasW wrote:
>
> Look at my blog.
> There is an example for file uploads.
> http://www.thomasweidner.com/flatpress/2008/11/01/file-transfer-hashing-and-other-news/
>
> Greetings
> Thomas Weidner, I18N Team Leader, Zend Framework
> http://www.thomasweidner.com
>
>

--
View this message in context: http://www.nabble.com/Zend_Form---Zend_File-Upload-to-DB-not-working-tp21693984p21707673.html
Sent from the Zend Framework mailing list archive at Nabble.com.




--
Michael Crumm
[hidden email]