忽略文件上传的空实例与Zend框架?文件因此无法上传
Ignore Empty instances of File upload With Zend Framework ? File not uploading because of it
我试图在ZF1中上传几个文件
有两个上传选项;音频或图像。当我试图上传图像时,只有file_audio的空实例有问题。
这是我的print $_FILES
Array
(
[image_file] => Array
(
[name] => boss.jpg
[type] => image/jpeg
[tmp_name] => C:'WINDOWS'Temp'phpA01.tmp
[error] => 0
[size] => 37246
[options] => Array
(
[ignoreNoFile] =>
[useByteString] => 1
[magicFile] =>
[detectInfos] => 1
)
[validated] =>
[received] =>
[filtered] =>
[validators] => Array
(
[0] => Zend_Validate_File_Upload
)
)
[audio_file] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] =>
[options] => Array
(
[ignoreNoFile] =>
[useByteString] => 1
[magicFile] =>
[detectInfos] => 1
)
[validated] =>
[received] =>
[filtered] =>
[validators] => Array
(
[0] => Zend_Validate_File_Upload
)
)
)
这是我的Zend代码它只在两个文件都被选中的情况下工作
if (! empty ( $post ['type'] )) {
$adapter = new Zend_File_Transfer ();
// echo "<pre>"; print_r($_FILES); "</pre>"; exit;
if ($post ['type'] == 'Image' && ! empty ( $_FILES ['image_file'] ['name'] )) {
$files = $adapter->getFileInfo();
echo "<pre>"; print_r($files); "</pre>"; exit;
$files = $adapter->getFileInfo();
$files_path = $config->topic_images->path;
// Limit the MIME type of all given files to gif and jpeg images
// $adapter->addValidator ( 'MimeType', false, array ('image/jpeg', 'image/png', 'image/jpg' ) );
// $adapter->addValidator ( 'Extension', false, 'png,jpeg,jpg' );
// $adapter->addValidator ( 'FilesSize', false, array ('min' => '1kB', 'max' => '5MB' ) );
// $adapter->addValidator ( 'ImageSize', false, array ('minwidth' => 0, 'maxwidth' => 800, 'minheight' => 0, 'maxheight' => 800 ) );
// Limit the size of a image to a height of 100-200 and a width of 40-80 pixel
}elseif($post ['type'] == 'Audio' && ! empty ( $_FILES ['audio_file'] ['name'] )) {
$files_path = $config->topic_audio->path;
}elseif($post ['type'] == 'Video' && ! empty ( $post ['video_file'] )) {
}
$files = $adapter->getFileInfo ();
$file_name = null;
$tmpArr = null;
$fname = null;
$fext = null;
foreach ( $files['image_file'] as $file => $info ) {
if (! empty ( $info ['name'] )) {
$fname = substr ( $info ['name'], 0, strrpos ( $info ['name'], "." ) );
$fext = substr ( $info ['name'], strrpos ( $info ['name'], "." ) );
}
}
if (! empty ( $fname )) {
$file_name = $fname . "-" . $post ['topic_id'] . $fext;
$horrible_chars = array ("~", "@", "#", "$", "%", "^", "&", "*", "(", ")", " " );
echo $cleanfilename = str_replace ( $horrible_chars, "", $file_name );
$adapter->setDestination ( $files_path );
// $adapter->addFilter ( 'Rename', array ('target' => $files_path . DS . $cleanfilename, 'overwrite' => true ) );
if ($adapter->receive ()) {
// echo "xxx"; exit;
$post ['filename'] = $cleanfilename;
$result = $TopicModel->updateTopicassociation ( $post );
$old_file = $files_path . DS . $post ['existing_file'];
if (file_exists ( $old_file )) {
if ($file_name != $post ['existing_file']) {
@unlink ( $old_file );
}
}
$this->_flashMessenger->addMessage ( 'Topic '.$post['type'].'added successfully' );
} else {
$errors = $adapter->getErrors();
print_r($errors); exit;
$post ['filename'] = null;
$res_delete = $TopicModel->updateTopicassociation ( $post ['topic_id'] );
$this->_flashMessenger->addMessage ( 'Error(s) encountered. File Association not updated.' );
}
}
// else {
// if (! empty ( $post ['chkDelete'] ) && $post ['chkDelete'] == 1) {
// $post ['filename'] = null;
// $result = $jobModel->updateJobLogo ( $post );
// $old_file = $files_path . DS . $post ['c_image_name'];
//
// if (file_exists ( $old_file )) {
// @unlink ( $old_file );
// }
// }
// }
}
我花了一整天的时间试图上传一个图像或音频文件。有人知道是什么问题吗?
更新为表单输入baseUrl()。"/"。$ this -> modulename;?>/主题/动作);?> ">
<input type="file" id="image_file" name="image_file">
</form>
<input type="text" name="video_file" size="50" id="video_file" />
尝试将ignoreNoFile
选项设置为true,这样如果没有文件适配器就不会抛出匹配:
$adapter = new Zend_File_Transfer ('HTTP', false, array('ignoreNoFile'=>true));
或
$adapter = new Zend_File_Transfer ();
$adapter->setOptions(array('ignoreNoFile'=>true))
我用jquery解决了
因为我提供了上传音频、视频和图像的选项
我只是检查了提交按钮下拉框中的值,并删除了文件上传的空实例
因为zend遇到了问题。
我使用了下面的代码,这很简单。
$('#cmdSubmit').click(
function(){
var selection = $("#type").val();
if( selection == 'Image'){
$('#videomodule').remove();
$('#audiomodule').remove();
}else if(selection == 'Audio'){
$('#imagemodule').remove();
$('#videomodule').remove();
}else if(selection == 'Video'){
$('#imagemodule').remove();
$('#audiomodule').remove();
}else{
$('#imagemodule').remove();
$('#videomodule').remove();
$('#audiomodule').remove();
}
});
它解决了我的问题,现在其他人可以给它一个尝试或尝试岩石以上的答案。
相关文章:
- 如何在另一个html文件的框架中包含图像
- 将本地文件传递给第三方框架
- 在企业应用程序框架中包含js/css文件的最佳实践是什么
- Angular.js框架的附加js文件用于什么
- jquery移动应用程序无法使用jquryMobile框架JS和css文件的相对路径
- 输入文件和自动提交 - 播放框架 2.
- 如何将文件上传到silverstripe框架中的asset文件夹中
- 带有外部JSON文件的Ionic框架
- 点击播放框架上的按钮后强制下载文件
- 打开任何文本/文档文件进行编辑,使用Javascript/DOJO/或基于框架的点击事件和Java进行编辑
- 在 Django 框架中的 js 文件中获取 JSON 数据
- 如何在使用弹簧框架工作时提供JSP页面的URL以打开WEB-INF文件夹中的弹出窗口
- 节点.js:加载HTML文件中包含的.js和.css文件,而不使用Express/框架
- 旧的(以前的html5)ajax文件上传框架是如何工作的
- 在nodeJS和Express框架中找不到文件时出错
- 将js和css文件添加到zend框架中的视图中
- 使用phonegap框架访问Android设备上的图像文件
- 如何在mvvm框架中使用敲除js最小化使用grunt的javascript文件
- 在没有框架的节点中提供jpeg文件
- 在js文件中播放框架控制器操作调用