Javascript 文件上载不适用于“模型”对话框?
如果只有文本字段要更新,则此代码有效。但当我试图上传任何文件时,它都无法上传。如果我在下面注释jQuery,那么它可以工作,但不会显示“模型中的错误”对话框 PHP脚本:Javascript 文件上载不适用于“模型”对话框?,javascript,php,jquery,html,file-upload,Javascript,Php,Jquery,Html,File Upload,如果只有文本字段要更新,则此代码有效。但当我试图上传任何文件时,它都无法上传。如果我在下面注释jQuery,那么它可以工作,但不会显示“模型中的错误”对话框 PHP脚本: <?php include_once 'db/Common.php'; include_once 'db/CustomerDB.php'; include_once 'db/CustomerDetails.php'; $cust_id= $_POST ['hidCustId']; function IsNullOr
<?php
include_once 'db/Common.php';
include_once 'db/CustomerDB.php';
include_once 'db/CustomerDetails.php';
$cust_id= $_POST ['hidCustId'];
function IsNullOrEmptyString($question){
return (!isset($question) || trim($question)==='');
}
$uploadSuccess=false;
$files = array_fill(0,8,NULL);
for ($i=1;$i<=8;$i++){
if(isset($_FILES['file'.$i])){
$errors= array();
$file_name = $_FILES['file'.$i]['name'];
$file_size =$_FILES['file'.$i]['size'];
$file_tmp =$_FILES['file'.$i]['tmp_name'];
$file_type=$_FILES['file'.$i]['type'];
$file_ext=strtolower(end(explode('.',$_FILES['file'.$i]['name'])));
$files[$i-1] = $file_name;
$expensions= array("jpeg","jpg","png","pdf","docs","doc","exe", "pages");
if(in_array($file_ext,$expensions)=== true){
//$errors['file'.$i]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 10097152){
$errors[]='File size must be bellow 10 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"uplodedfile/".$file_name);
$uploadSuccess=true;
}else{
print_r($errors);
}
}
}
$customerDB = new CustomerDB ();
$customers = new CustomerDetails ();
$customerArray = $customerDB->selectAllCustomers($cust_id, null, null, null, null);
$customer = $customerArray[0];
$files_old = $customer->get_custFiles();
for($i=0; $i<=7; $i++){
if(IsNullOrEmptyString($files[$i])){
if(!IsNullOrEmptyString($files_old[$i])){
$files[$i] = $files_old[$i];
}
}
}
$customerDB->updateFiles($cust_id,$files);
if ($uploadSuccess) {
$msgs = "Files updated successfully";
} else {
$errorMsg = "Error while updating Files details.";
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<!-- Viewport Metatag -->
<?php $common = new Common(); echo $common->get_include_contents('include/css.php')?>
</head>
<body>
<?php
if (! empty ( $msgs )) {
?>
<div class="mws-form-message success">
This is a success message
<ol>
<li><?php echo $msgs; ?></li>
<li>Close this dialog box to continue.</li>
</ol>
</div>
<?php }elseif ($errorMsg){ ?>
<div class="mws-form-message error">
This is an error message
<ul>
<li><?php echo $errorMsg; ?></li>
</ul>
</div>
<?php }?>
尝试声明$errorMsg=“”;在像您这样的Startook中,除了
$\u文件['file.'$i]['error']]
之外,您使用$\u文件数组中的每一条数据,检查PHP是否试图告诉您一些事情是否有用,这很奇怪,您需要完成所有上传,然后再检查并修改数据库。您为什么不在执行move\u uploaded\u file()的位置执行此操作
$(document).on('submit', '#formEditFiles', function(event)
{
event.preventDefault();
var data = $(this).serialize();
$.ajax({
type : 'POST',
url : 'handleFilesEvent.php',
data : data,
success : function(response)
{
$(".quickNote").html(response);
}
});
return false;
});