Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 489983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:51:47+00:00 2026-05-13T01:51:47+00:00

I want to upload an image with Zend Framework version 1.9.6. The uploading itself

  • 0

I want to upload an image with Zend Framework version 1.9.6. The uploading itself works fine, but I want a couple of other things as well … and I’m completely stuck.

  • Error messages for failing to upload an image won’t show up.
  • If a user doesn’t enter all the required fields but has uploaded an image then I want to display the uploaded image in my form. Either as an image or as a link to the image. Just some form of feedback to the user.
  • I want to use Zend_ Validate_ File_ IsImage. But it doesn’t seem to do anything.
  • And lastly; is there some automatic renaming functionality?

All ideas and suggestions are very welcome. I’ve been struggling for two days now.

These are simplified code snippets:

myform.ini

method = "post"

elements.title.type = "text"
elements.title.options.label = "Title"
elements.title.options.attribs.size = 40
elements.title.options.required = true

elements.image.type = "file"
elements.image.options.label = "Image"
elements.image.options.validators.isimage.validator = "IsImage"

elements.submit.type = "submit"
elements.submit.options.label = "Save"

TestController

<?php
class Admin_TestController extends Zend_Controller_Action
{
  public function testAction ()
  {
    $config = new Zend_Config_Ini(MY_SECRET_PATH . 'myform.ini');
    $f = new Zend_Form($config);

    if ($this->_request->isPost())
    {
      $data = $this->_request->getPost();

      $imageElement = $f->getElement('image');
      $imageElement->receive();

      //$imageElement->getValue();

      if ($f->isValid($data))
      {
        //save data
        $this->_redirect('/admin');
      }

      else
      {
        $f->populate($data);
      }
    }

    $this->view->form = $f;
  }
}
?>

My view just echo’s the ‘form’ variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:51:48+00:00Added an answer on May 13, 2026 at 1:51 am

    First, put this at the start of your script:

    error_reporting(E_ALL);//this should show all php errors

    I think the error messages are missing from the form because you re-populate the form before you display it. I think that wipes out any error messages. To fix that, remove this part:

    else
    {
       $f->populate($data);
    }
    

    To show the uploaded image in the form, just add a div to your view template, like this:

    <div style="float:right"><?=$this->image?></div>
    

    If the image uploaded ok, then populate $view->image with an img tag.

    As for automatic re-naming, no, it’s not built in, but it’s very easy. I’ll show you how below.
    Here’s how I handle my image uploads:

    $form = new Zend_Form();
    $form->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
    
    $image = new Zend_Form_Element_File('image');
    $image->setLabel('Upload an image:')
          ->setDestination($config->paths->upload)
          ->setRequired(true)
          ->setMaxFileSize(10240000) // limits the filesize on the client side
          ->setDescription('Click Browse and click on the image file you would like to upload');
    $image->addValidator('Count', false, 1);                // ensure only 1 file
    $image->addValidator('Size', false, 10240000);            // limit to 10 meg
    $image->addValidator('Extension', false, 'jpg,jpeg,png,gif');// only JPEG, PNG, and GIFs
    
    $form->addElement($image);
    
    $this->view->form = $form;
    
    if($this->getRequest()->isPost())
    {
        if(!$form->isValid($this->getRequest()->getParams()))
        {
            return $this->render('add');
        }
    
        if(!$form->image->receive())
        {
            $this->view->message = '<div class="popup-warning">Errors Receiving File.</div>';
            return $this->render('add');
        }
    
        if($form->image->isUploaded())
        {
            $values = $form->getValues();
            $source = $form->image->getFileName();
    
            //to re-name the image, all you need to do is save it with a new name, instead of the name they uploaded it with. Normally, I use the primary key of the database row where I'm storing the name of the image. For example, if it's an image of Person 1, I call it 1.jpg. The important thing is that you make sure the image name will be unique in whatever directory you save it to.
    
            $new_image_name = 'someNameYouInvent';
    
            //save image to database and filesystem here
            $image_saved = move_uploaded_file($source, '/www/yoursite/images/'.$new_image_name);
            if($image_saved)
            {
                $this->view->image = '<img src="/images/'.$new_image_name.'" />';
                $form->reset();//only do this if it saved ok and you want to re-display the fresh empty form
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i want to upload image on server and i have done it but
Hello Friends I want to upload a image but according to requirement when click
i want to upload an image from the client's system, through javascript and store
i want to upload profile pic like facebook and ajax upload the image and
I'm trying to upload image files. When uploading files of sizes of about 40
I have xml file with collection image urls and I want upload this url
I want my customers to upload some file to my server. My current design
I have a button labeled Upload image, when you click the button it opens
I have a form that contains and form of which code goes like this
If a website user submits an HTML form with: (1) a post method; (2)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.