display images

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

display images

ankuraeran
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
Reply | Threaded
Open this post in threaded view
|

1.7.1 Zend_Controller_Request_Http Error

Steven Brown-7
Hi guys,

I am getting the following in ZF 1.7.1:

Error Number: 2
Error Type: PHP WARNING
Error String: strstr(): Empty delimiter.
Error File: /path/to/my/site/library/Zend/Controller/Request/Http.php
Error Line: 393

The line is:

if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri,
$_SERVER['HTTP_HOST'])) {

I am running a PHP file from the command line, it has:

$_SERVER['REQUEST_URI'] = '/transcode/';
$_SERVER['HTTP_HOST'] = '';
// Bootstrap code etc. etc.

This worked in 1.7.0...should I change my code or should ZF be changed?

Cheers,
Steven


Reply | Threaded
Open this post in threaded view
|

RE: 1.7.1 Zend_Controller_Request_Http Error

Marco Kaiser-2
Hi Steven,

you change a super global variable!!!!
From any value to '' (empty String) so this warning is correct.
Change your Code !

-- Marco

-----Original Message-----
From: Steven Brown [mailto:[hidden email]]
Sent: Monday, December 08, 2008 12:42 PM
To: [hidden email]
Subject: [fw-general] 1.7.1 Zend_Controller_Request_Http Error

Hi guys,

I am getting the following in ZF 1.7.1:

Error Number: 2
Error Type: PHP WARNING
Error String: strstr(): Empty delimiter.
Error File: /path/to/my/site/library/Zend/Controller/Request/Http.php
Error Line: 393

The line is:

if (isset($_SERVER['HTTP_HOST']) && strstr($requestUri,
$_SERVER['HTTP_HOST'])) {

I am running a PHP file from the command line, it has:

$_SERVER['REQUEST_URI'] = '/transcode/';
$_SERVER['HTTP_HOST'] = '';
// Bootstrap code etc. etc.

This worked in 1.7.0...should I change my code or should ZF be changed?

Cheers,
Steven


Reply | Threaded
Open this post in threaded view
|

Re: display images

Michael Crumm
In reply to this post by ankuraeran
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 <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|

Re: display images

ankuraeran
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/application/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) :  ?>
        <img src='<?= $this->img; ?>' alt="restra image" >
<? 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 <ankur@osscube.com> 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.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: display images

Rolando Espinoza La Fuente
On Tue, Dec 9, 2008 at 2:34 AM, ankuraeran <[hidden email]>
[...]
>                                $this->view->img  = APPLICATION_PATH . 'uploads/'.$uploadedData['file'];

I guess you are trying to display the image uploaded. But you are storing
the image inside application path, which usually isn't accesible via web.

Depends on your structure, but usually:

/path/to/project
                         /application          <- APPLICATION_PATH
                         /public                   <- public directory

And uploads should be stored in /public/uploads
so you can use in your view scripts <img src="/uploads/pic.jpg" />

Hope that helps.

Regards,

--
Rolando Espinoza La fuente
Pro Soft Resources  Inc.
www.prosoftpeople.com