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

  • Home
  • SEARCH
  • 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 8812601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:38:26+00:00 2026-06-14T03:38:26+00:00

Below you will find my function for the uploadAction. This code works. I am

  • 0

Below you will find my function for the uploadAction. This code works. I am able to get images. However, I want to integrate an automatic resize mechanism to the code. Can someone explain to me how I could force files I am uploading in this upload Action to be parsed through my resizing function.

  public function uploadAction()
    {
        $request = $this->getRequest();

        $error = null;

        if ($request->isPost()) {
            if ($request->getParam('submit')) {

            // Create upload object
            $upload = new Zend_File_Transfer();

            // Add our validators
            $upload->addValidator('Size', false, 102400);
            $upload->addValidator('Extension', false, 'jpg,png,gif');

            // Set our destination
            $upload->setDestination(APPLICATION_PATH . '/../public/images/blog/');

                if(!$upload->receive()) {
                    $messages = $upload->getMessages();

                    foreach ($messages as $type => $message) {
                        switch($type) {
                            case 'fileExtensionFalse':
                                $this->view->error = 'File must be an image (jpg, gif, png)';
                                break;
                            case 'fileUploadErrorNoFile':
                                $this->view->error = 'Please select a file to upload';
                                break;
                            default:
                                $this->view->error = implode("/n", $messages);
                                break;
                        }
                    }
                }
                    print_r($messages); die();
            }
        }
    }

RESIZING FUNCTION

 public function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 4)
    {
        if (empty($src_image) || empty($dst_image)) { return false; }
            if ($quality <= 1)
            {
                $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
                imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
                imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
                imagedestroy ($temp);
            }
            elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h))
            {
                $tmp_w = $dst_w * $quality;
                $tmp_h = $dst_h * $quality;
                $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
                imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
                imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
                imagedestroy ($temp);
            } else
            {
                imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
            }
            return true;
    }

I want to be able to change the size of the image and the quality as it is uploaded. What is the function or call to access the file I JUST uploaded or can I manipulate the file before it is saved? Like upload the file, pass it through my function, then have the ouput from that become my “saved” file?

  • 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-06-14T03:38:27+00:00Added an answer on June 14, 2026 at 3:38 am

    Create your own filter.

    http://framework.zend.com/manual/1.12/en/zend.filter.writing_filters.html

    class Resize implements Zend_Filter_Interface
    {
        public function filter($value)
        {
            // perform some transformation upon $value to arrive on $valueFiltered
    
            return $valueFiltered;
        }
    }
    

    In the filter method you will receive the path to the uploaded file. Resize it over there and return the new path. Then you can assign this filter in the upload object:

    $upload->addFilter("Resize");
    

    Detailed explanation of Zend_File_Transfer filters here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a homework project that requires this: Below you will find the code
I have the code below that will open a modal window. This works in
The code below will find an image if it exists and move it above
I am trying to send SMS using php's mail() function. Below you will find
Below you will find my current vHost entry that I am using for a
thanks for taking the time to stop by my question. Below you will find
The code below will validate required fields within currently visible fieldsets, but only if
The code below will report Syntax error message: type 'a edge = |Empty |End
I need a function that will go through below values and print out the
I have a piece of code which will find out the repeating elements in

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.