【发布时间】:2014-12-23 19:11:28
【问题描述】:
我使用 BootstrapValidation 为 PhpExcel 验证文件。
Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open for reading! File does not exist.'
1:如何将验证设置为不仅接受 .xls 还接受整个文件名 (file.xls)?
2: 文件不 POST? (见脚本)
HTML:(我需要 input name ="avatar" 才能让 BootstrapValidation 工作)
<form id="fileForm" class="form-horizontal well" action='php/import_excel.php' method="post">
<div class="form-group">
<h4>Välj fil...</h4>
<div class="col-sm-12">
<input type="file" class="form-control" id="file" name="avatar" />
</div>
</div>
<div class="pull-right">
<button type="submit" id="Import" name="Import" class="btn btn-primary button-loading" data-loading-text="Loading...">Ladda upp</button>
</div>
<br />
</form>
JS:
$(document).ready(function() {
$('#fileForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
avatar: {
validators: {
file: {
extension: 'xls',
type: 'application/vnd.ms-excel',
message: 'Välj: lkbkom.xls'
}
}
}
}
});
});
PHP:
if(isset($_POST["Import"])){
echo $path=$_FILES["file"]["tmp_name"];
【问题讨论】:
-
HTML -> 你忘记设置加密 enctype="multipart/form-data"
-
@donald123 我试过了,还是不行!
标签: javascript php jquery