hrnsky
hrnsky

Reputation: 121

zend framework multiple input file upload

i have a form that contains two file element with unique name. i want to reach each file element from Zend_File_Transfer_Adapter_Http(); how can i do that? if i use

$apt = new Zend_File_Transfer_Adapter_Http();
.
.
$apt->receive();

two files have been uploaded. but i execute different queries for each file element.

for example

$smallPic = small pic name that i get from input smallPic
i execute 
update products set smallPic = '$smallPic'
and for large pic
$largePic = large pic name that i get from input largePic
i execute 
update products set largePic = '$largePic'

how can i reach each input file element with $apt ?

Upvotes: 2

Views: 4357

Answers (1)

drew010
drew010

Reputation: 69957

Here is some code I have used in the past to receive multiple files from a Zend_Form where many of the file upload fields were dynamic and not part of the form.

Since you know the names of the two file uploads, you can also say $apt->getFileInfo('my_file');

$apt    = new Zend_File_Transfer_Adapter_Http();
$files  = $apt->getFileInfo();

foreach($files as $file => $fileInfo) {
    if ($apt->isUploaded($file)) {
        if ($apt->isValid($file)) {
            if ($apt->receive($file)) {
                $info = $apt->getFileInfo($file);
                $tmp  = $info[$file]['tmp_name'];
                $data = file_get_contents($tmp);
                // here $tmp is the location of the uploaded file on the server
                // var_dump($info); to see all the fields you can use
            }
         }
     }
}

Hope that helps.

Upvotes: 5

Related Questions