Question

I want to check if a file has been uploaded or not. If not I don't want my form to update this field automatic. If it is uploaded I want this file to be uploaded in my db. Here is the code in my controller. In my form I've got an Zend_Form_Element_File('Document')

$upload = new Zend_File_Transfer();
$data['document'] = $upload->getFileInfo();
foreach ($data['document'] as $file => $info) {
  if ($upload->isUploaded($file)) {
  }
  if (!$upload->isUploaded($file)) {
  }
  // ...?
}

Thanks

Was it helpful?

Solution 2

Got the answer myself:

if ($data['document'] == null)
{
    unset($data['document']);
}

if nothing is added to the form while editing it. You only have to check if the array is null or not. If $data['document'] == null then you have to unset this $data['document'] so it will not be replaced with null and the old files will still be

OTHER TIPS

From the Zend documentation for the Zend_Form_Element_File class, with comments added:

// check whether a file has been uploaded
if (!$form->foo->receive()) {
    print "Error receiving the file";
}

// get the file name
$location = $form->foo->getFileName();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top