Zend isUploaded with multidimensional POST

28th September 2013

While developing TypeCMS I came across a difficulty with Zend_File_Transfer_Adapter_Http::isUploaded, multidimensional POST data and multiple file fields. The difficulty is in the parameter you give to isUploaded.

Say for example we have this form:

<form method="post" enctype="multipart/form-data">
    <input type="file" name="typecms[file1]" />
    <input type="file" name="typecms[file2]" />
</form>

If you would choose files for both file fields then you can check whether or not it uploaded using the following:

$adapter = new Zend_File_Transfer_Adapter_Http();
if ($adapter->isUploaded('typecms')) {
    echo 'Uploaded!';
}

This would detect if both file fields were filled, but when you would only use file1 the above would not echo "Uploaded!" because file2 is empty.

To only check if file1 is uploaded you do the following:

$adapter = new Zend_File_Transfer_Adapter_Http();
if ($adapter->isUploaded('typecms_file1_')) {
    echo 'Uploaded!';
}

This will check if file1 is uploaded and echo "Uploaded!".

comments powered by Disqus