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 3487620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:10:16+00:00 2026-05-18T11:10:16+00:00

I have a form that contains and form of which code goes like this

  • 0

I have a form that contains and form of which code goes like this for image

$image->setDestination(APPLICATION_PATH . '/../public/images/upload'); 

and in my controller i have

if($countryForm->image->isUploaded())
{ 
  $countryForm->image->receive();    
  $countryModel->addCountry(
    $countryForm->getValue('name'), 
    $countryForm->getValue('description'),
    $this->view->baseUrl('/images/upload/'.basename($countryForm->image->getFileName()))
  );
}

how can i change the name of the filename uploaded. I want to set it to

random(100).time().ext

trying this code

 if($form->image->isUploaded()){
   $upload = new Zend_File_Transfer();
   $upload->addFilter('Rename', array('target' => APPLICATION_PATH.'/../images/upload/'.time().'.jpg', 'overwrite' => true));
   $form->image->receive();
   $filename = $form->image->getFilename(); 
   $pageModel->addPage($form->getValue('pagetitle'),
   $form->getValue('pagemetakeyword'),
   $form->getValue('pagemetadescription'),
   $form->getValue('pagecategory'),
   $filename,
   $form->getValue('pagecontent'),
   $form->getValue('pagestatus')
  );   

}

would still give ‘backend/public/images/upload/picture.jpg’ in my database

I have in my form the following code

 $image = $this->createElement('file', 'image'); 
 $image->setLabel('Image: '); 
 $image->setRequired(FALSE); 
 $image->setDestination(APPLICATION_PATH . '/../public/images/upload/'); 
 $image->addValidator('Count', false, 1); 
 $image->addValidator('Size', false, 1024000); 
 $image->addValidator('Extension', false, 'jpg,jpeg,png,gif'); 
 $this->addElement($image); 

and i am using Ubuntu

  • 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-18T11:10:17+00:00Added an answer on May 18, 2026 at 11:10 am

    Use addFilter()

    http://framework.zend.com/manual/1.12/en/zend.file.transfer.filters.html#zend.file.transfer.filters.usage

    If you include the filename (here you can use your rand() function) and add it to the target array value it will rename it

    From documentation:

    $upload = new Zend_File_Transfer();
    
    // Set a new destination path
    $upload->addFilter('Rename', 'C:\picture\uploads');
    
    // Set a new destination path and overwrites existing files
    $upload->addFilter('Rename', array('target' => 'C:\picture\uploads', 'overwrite' => true));
    

    Try:

        if($form->image->isUploaded()){
           $upload = new Zend_File_Transfer();
           $files = $upload->getFileInfo();
           //You should also add file validation, see:
     //http://framework.zend.com/manual/en/zend.file.transfer.introduction.html#zend.file.transfer.introduction.checking
           $upload->addFilter('Rename', APPLICATION_PATH.'/../images/upload/'.time().'.jpg', $files[0]);
           $upload->receive($files[0]);
           $filename = $files[0]->getFilename(); 
           $pageModel->addPage($form->getValue('pagetitle'),
           $form->getValue('pagemetakeyword'),
           $form->getValue('pagemetadescription'),
           $form->getValue('pagecategory'),
           $filename,
           $form->getValue('pagecontent'),
           $form->getValue('pagestatus')
          );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that contains a GridView control which is databound to an
I have asp.net form that contains fields. When I access this window, my javascript
I would like to have an aspx page that contains something like.... <form id=form1
In my HTML code, I have a form tag that contains two input boxes,
I have created a macro for excel which will pop up form that contains
I have a php file that contains a form (which contains 2 input boxes
I have following code that is accepting a form submission [ActionName(TestingTemp), AcceptVerbs(HttpVerbs.Post)] public ActionResult
I have a form that contains a bunch of checkboxes. Before submitting the form,
I have a form element that contains multiple lines of inputs. Think of each
I have an asp.net text form that contains numerous decimal fields that are optional.

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.