Weird title, yes, but the problem is simple; simply aggrevating. 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 the chunk of code from my controller that is handling the upload. There's actually a little more, but this is the relevant piece:
$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())
It's pretty straight forward. The $data stuff is just me grabbing the filename if it's there or setting the variable to NULL. I have my addFilter() and addValidator() segmented out to only affect their relevant files in this case "image" or "file" - the names of the form fields.
The "file" upload always works! However, the "image" upload doesn't and what's more it puts the temporary file into the RESOURCES_FILES directory which makes no sense at all. So that directory has PDFs and whatever else in addition to files like php8TJT13, phpXmOzQM, etc.
I have been staring at this code and searching through Stack Overflow and whatever Google will turn up and I can't find anyone having this problem. Help!