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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:03:26+00:00 2026-06-01T02:03:26+00:00

i have an issue with uploading multiple files to disk. here is my code.

  • 0

i have an issue with uploading multiple files to disk. here is my code.

i have a request with 2 pictures that gets sent to a upload function. the 2 pictures are in a var called $multiUpload

$folderPath = '/var/www/';
if (is_array($multiUpload)){
            $file = array();
            $filename = array();

            foreach($multiUpload as $key=>$val){
                // get the file extension
                $file[] = explode('.',$val);

                // create custom file name
                $filename[] = time().'.'.$file[$key][1];

                //send to the upload function
                $this->uploadToDisk($folderPath, $filename[$key]);

                // sleep 1 sec so that the pic names will be different
                sleep(1);
            }
                 return $filename;

        }


public function uploadToDisk($folderPath, $filename)
{

    $adapter = new Zend_File_Transfer_Adapter_Http();
    $adapter->setDestination($folderPath);
    $adapter->addFilter( 'Rename',array(
            'target' => $folderPath."/".$filename,
            'overwrite' => true
            ) );
    if ($adapter->receive()) {
        $message = "success";
    } else {
        $message = "fail";
    }

    return $message;
}

this will return

Array
(
    [0] => Array
        (
            [0] => 1332977938.jpg
            [1] => 1332977939.jpg
        )

)

but only array[0][0] or 1332977938.jpg will actually get saves to the disk.

Why are they now both get saved? wired

any ideas?

  • 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-01T02:03:27+00:00Added an answer on June 1, 2026 at 2:03 am

    I suspect the second call to uploadToDisk is returning fail because you can only call Zend_File_Transfer_Adapter_Http::receive() once for each file. Since you are not specifying a file when calling receive, it is receiving all of the files the first time you call uploadToDisk and subsequently is failing with a File Upload Attack error.

    Here is some code you can try. This tries to receive each file individually and then save them one at a time with each call to uploadToDisk.

    A few notes about the code:

    • The first parameter to uploadToDisk ($val) may need to be changed as I am not sure what the original values are. It should correspond to one of the element names used for the file upload (See Zend_File_Transfer_Adapter_Http::getFileInfo()) for a list of the files.
    • I changed the method for generating a unique filename so you don’t have to sleep(1)
    • Zend_File_Transfer_Adapter_Abstract::setDestination() is deprecated and will go away in the future. Instead, just use the Rename filter. When using Rename, setDestination() has no effect.

    And here it is…

    <?php
    
    $folderPath = '/var/www/';
    
    if (is_array($multiUpload)){
        $filenames = array();
    
        foreach($multiUpload as $key => $val){
            // get the file extension
            $ext = explode('.', $val);
            $ext = $ext[sizeof($ext) - 1];
    
            // create custom file name
            do {
                $filename = uniqid(time()) . '.' . $ext;
                $diskPath = $folderPath . $filename;
            } while (file_exists($diskPath));
    
            $filenames[$key] = $filename;
    
            //send to the upload function
            // $val is the file to receive, $diskPath is where it will be moved to
            $this->uploadToDisk($val, $diskPath);
        }
    
        return $filename;
    }
    
    
    public function uploadToDisk($file, $filename)
    {
        // create the transfer adapter
        // note that setDestination is deprecated, instead use the Rename filter
        $adapter = new Zend_File_Transfer_Adapter_Http();
        $adapter->addFilter('Rename', array(
                'target'    => $filename,
                'overwrite' => true
        ));
    
        // try to receive one file
        if ($adapter->receive($file)) {
            $message = "success";
        } else {
            $message = "fail";
        }
    
        return $message;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue when uploading files to tomcat. It seems that tomcat
I have a .NET 3.5 website that is uploading files to a SQL Server
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have an issue that is driving me a bit nuts: Using a UserProfileManager
I have a control that uploads 1..n files in chunks to a WCF service
I have trouble uploading files with SWFUpload when target servlet is listening on HTTPS.
While uploading images files on the live server I have stuck in a strange
I've an issue with uploading files with Drupal CCK fields. The issue is client-side.
I have quite of bit of data that I will be uploading into Google
I looked at this question: Uploading multiple files with Django but it did not

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.