Zend_File_Transfer with multiple files does not load the same

A strange name, yes, but the problem is simple; just aggressive. I have a form that I built without using Zend_Form, and it has two file uploads:

<input name="image" type="file" />
<input name="file" type="file" />

Here is a piece of code from my controller that handles the download. There's actually a bit more, but this is an important part:

$data['image'] = (isset($_FILES["image"]) && $_FILES["image"]["name"] ? $_FILES["image"]["name"] : NULL);
$data['file'] = (isset($_FILES["file"]) && $_FILES["file"]["name"] ? $_FILES["file"]["name"] : NULL);

$options = array('ignoreNoFile' => TRUE);
$upload = new Zend_File_Transfer();

$upload->setOptions($options)
       ->addFilter('Rename', array('target' => RESOURCES_IMG . $data['image'], 'overwrite' => TRUE), 'image')
       ->addFilter('Rename', array('target' => RESOURCES_FILES . $data['file'], 'overwrite' => TRUE), 'file')
       ->addValidator('ImageSize', false, array('minwidth'  => 100,
                                                'maxwidth'  => 100,
                                                'minheight' => 100,
                                                'maxheight' => 100), 'image')
       ->addValidator('Extension', false, 'jpg', 'image');

if (!$upload->isValid())
{
 echo '<h1>Oops</h1><p>Please correct the following errors: <hr /></p>';

 foreach ($upload->getMessages() as $key => $val)
 {
  echo '<p><strong>' . $key . '</strong><br />' . $val . '</p>';
 }
 die;
}
else
{
 $upload->receive();
} // if (!$upload->isValid())

This is pretty straight forward. $ Data stuff is just grabbing the file name if it's there, or setting the variable to NULL. I have my addFilter () and addValidator () segmented to affect only their respective files in this case "image" or "file" are the names of the form fields.

! , "" RESOURCES_FILES, . PDF , php8TJT13, phpXmOzQM ..

Qaru , Google , -, . !

+3
1

, , , , , addFilter(), , . . :

$data['image'] = (isset($_FILES["image"]) && $_FILES["image"]["name"] ? $_FILES["image"]["name"] : NULL);
$data['file'] = (isset($_FILES["file"]) && $_FILES["file"]["name"] ? $_FILES["file"]["name"] : NULL);

$upload = new Zend_File_Transfer();

$files = $upload->getFileInfo();

$options = array('ignoreNoFile' => TRUE);
$upload->setOptions($options);

foreach ($files as $field => $contents)
{
 if(!strlen($contents["name"]))
 {
  continue;
 }

 // upload instructions for image
 if ($field == 'image')
 {
  $upload->addFilter('Rename', array('target' => RESOURCES_IMG . $data['image'], 'overwrite' => TRUE), 'image')
         ->addValidator('ImageSize', false, array('minwidth'  => 100,
                                                  'maxwidth'  => 100,
                                                  'minheight' => 100,
                                                  'maxheight' => 100), 'image')
         ->addValidator('Extension', false, 'jpg', 'image');
 }

 // upload instructions for file
 if ($field == 'file')
 {
  $upload->addFilter('Rename', array('target' => RESOURCES_FILES . $data['file'], 'overwrite' => TRUE), 'file');
 }

 if(!$upload->receive($field)) {
  echo '<h1>Oops</h1><p>Please correct the following errors: <hr /></p>';

  foreach ($upload->getMessages() as $key => $val)
  {
   echo '<p><strong>' . $key . '</strong><br />' . $val . '</p>';
  }
  die;
  //return;
 }
} // foreach

Pseudo

getFileInfo(), , . for , , . , NULL, , continue.

, , . , Zend.

, - , . Zend, , , . "Zend" , , .

, addFilter(), . №3 ():

. , , .

http://framework.zend.com/manual/1.11/en/zend.file.transfer.filters.html

, , , " upload", , , :

http://www.pc-freak.net/blog/tag/uploading-multiple-files-from-a-form-with-zend-framework-zf-storing-uploaded-zf-files-with-unique-name/

+4

All Articles