Php Zend文件传输:上载单个图像时出现问题
我无法理解->isupload()是如何工作的。我想上传六张图片显示在我的索引页面上。现在的问题是,在我的更新函数中,如果我只上传一个或两个图像$upload->isupload()返回一个假值,但如果我决定更新所有六个图像,它将返回一个真值。我如何处理这个问题?我是不是遗漏了什么 这是我的zend文件传输上传Php Zend文件传输:上载单个图像时出现问题,php,zend-framework,zend-file,Php,Zend Framework,Zend File,我无法理解->isupload()是如何工作的。我想上传六张图片显示在我的索引页面上。现在的问题是,在我的更新函数中,如果我只上传一个或两个图像$upload->isupload()返回一个假值,但如果我决定更新所有六个图像,它将返回一个真值。我如何处理这个问题?我是不是遗漏了什么 这是我的zend文件传输上传 $upload = new Zend_File_Transfer(); $upload->addValidator('Count', false, array('min' =>
$upload = new Zend_File_Transfer();
$upload->addValidator('Count', false, array('min' =>1, 'max' => 6))
->addValidator('Size', false, array('max' => '1Mb'))
->addValidator('ImageSize', false, array('minwidth' => 50,
'maxwidth' => 1000,
'minheight' => 50,
'maxheight' => 1000));
if ($upload->isUploaded()) $hasImage = true;
改用
一旦您知道您的上传通过了验证程序,然后开始处理图像。默认情况下,Zend猜测所有上传的文件都是无效的,即使只有一个提交的表单文件字段是空的。 建议Zend文档在
receive()
之前调用isValid()
方法来覆盖此行为。
因此,我不确定是否建议最佳解决方案,但它对我有效:
$upload = new Zend_File_Transfer();
$upload->setDestination( 'some your destination' );
if( $adapter->isValid( 'your form file field name' ) ){
$adapter->receive( 'your form file field name' );
}
依此类推,每个文件字段名。如果需要的话,用
foreach
。@Niklas-Yup也试过了。但它不起作用。如果我不上传6张图片,它就不能将$hasImage设置为true。@Varun$upload->isValid()
返回false
?@Nklas是!因为它没有将$hasImage设置为true。但是如果我上传了所有代码,则会将其设置为真。@Varun您可以发布其余的代码吗?因为如果没有验证代码,则会出现其他错误。@Niklas根据文档“supload($files=null):此方法将检查用户是否上载了指定的文件。当您定义了一个或多个可选文件时,此方法非常有用。如果未指定任何文件,则将检查所有文件。“可选文件的含义是什么?”?如何定义可选文件?
$upload = new Zend_File_Transfer();
$upload->setDestination( 'some your destination' );
if( $adapter->isValid( 'your form file field name' ) ){
$adapter->receive( 'your form file field name' );
}