Dear Mike,

First of all thanks for your reply.

Actually, the code you mentioned works well for setting http headers but I
do not want to set header. I just want to browse the image from a location
out side of Apache's Document root. In my case I put all user uploaded
images in application_dir/data/uploads. 

It is bit strange that using the following code I can see the image in IE
but somehow it doew not display in firefox.


public function uploadAction()
    {
                $this->view->headTitle('Home');
        $this->view->title = 'Upload image';
        $this->view->bodyCopy = "<p>Please fill out this form.</p>";

        $form = $this->getUploadForm();;

        if ($this->_request->isPost()) 
                {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) 
                        {
                // success - do something with the uploaded file
                $uploadedData = $form->getValues();
                $fullFilePath = $form->file->getFileName();
                                $this->view->filePath = $fullFilePath;
                                $this->view->isFileUploaded = 1;
                                $this->view->img  = APPLICATION_PATH . 
'uploads/'.$uploadedData['file'];
                        }
                        else 
                        {
                $form->populate($formData);
            }
        }
        $this->view->form = $form;
        }

and upload.phtml contains:
<?php if ($this->isFileUploaded) :  ?>
         '<?= $this- img; ?>' alt="restra image" ></img>
<? else : ?>
        <?php echo $this->form->render(); ?>    
<? endif; ?>

Am I making any mistake?

With regards,
Ankur


Michael Crumm wrote:
> 
> Ankur,
> 
> If by 'path ambiguity' you mean that your image files are stored outside
> your webroot, then i think i can at least lead you in the right direction.
> 
> I use a controller action to output an image from the file system.  The
> easiest way to do this is to grab ahold of the response object from within
> your controller action and set the appropriate headers and content for the
> media you want to output.
> 
> Here's my controller file:
> 
> <?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();
>     }
> }
> 
> 
> I purposefully included the beginning php tag so that you would see that I
> omitted the closing tag.  This is good practice all the time, but
> invaluable
> here.  An additional whitespace following a closing tag in this instance
> would result in the image not appearing in the browser.
> 
> getimagesize(), filesize(), and file_get_contents() you are most likely
> already familiar with.  If not, take a quick trip to php.net for some more
> info.  (fyi, the name getimagesize is misleading.  it does more than
> that.)
> 
> Hope this helps.
> 
> -Mike
> 
> The only rea
> 
> On Mon, Dec 8, 2008 at 1:20 AM, ankuraeran <[EMAIL PROTECTED]> wrote:
> 
>>
>> I am newbie to ZF. I could successfully create file upload action but due
>> to
>> some path abbiguity I am unable to display that uploaded image in browse.
>> The path where I put the uploaded image is
>>
>> <myapplication>/data/uploads/
>>
>> Will anybody please guide me how to access the image in template.
>>
>> Regards,
>> Ankur
>> --
>> View this message in context:
>> http://www.nabble.com/display-images-tp20890555p20890555.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: 
http://www.nabble.com/display-images-tp20890555p20909531.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to