无法上传jpg以外的任何内容

时间:2012-03-28 06:30:12

标签: php zend-framework image-uploading

我在zf应用程序中上传此代码:

public function uploadAction() {
    $upload = new Zend_File_Transfer_Adapter_Http();
    $upload->setDestination("uploads");
    if (!$upload->isValid()) {
        throw new Zend_Exception("Upload Error");
    }
    try {
        $upload->receive();
    } catch (Zend_File_Transfer_Exception $e) {
        throw new Zend_Exception('Upload Error ' . $e->getMessage());
    }


    $this->_helper->viewRenderer->setNoRender();
}

并跟随html:

<form enctype="multipart/form-data" action="admin/upload" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="Filedata" type="file" /><br />
<input type='hidden' name='MAX_FILE_SIZE' value='10000' />
<input type="submit" value="Upload File" />
</form>

jpg文件的一切正常......但我在JPG和png等上得到了zend例外:

  

致命错误:第2539行D:\ xampp \ htdocs \ sc \ application \ controllers \ AdminController.php中未捕获的异常'Zend_Exception',消息'上传错误'   (!)Zend_Exception:在第2539行的D:\ xampp \ htdocs \ sc \ application \ controllers \ AdminController.php中上传错误

我调试了异常和var dump validator消息......发现了这个:

array


'fileUploadErrorFormSize' => string 'File 'Filedata' exceeds the defined form size' (length=45)

1 个答案:

答案 0 :(得分:1)

您只需要一个<input type='hidden' name='MAX_FILE_SIZE' value='10000' />语句。 10000有点小,因为这意味着你只限于一个10Kb的文件......