windows 下jquery+ajax+php文件上传,linux+nginx+php+mysql 出问题.....  有个选择文件路径后js检测后缀的也不弹出了,提交后到不了 接受不到任何东西....wnmp下写的。jquerywindowsajaxlinuxnginx

解决方案 »

  1.   


    html 
    <?php
    /******************************************
    ajax上传入口
    ******************************************/
    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>导入程序</title>
    <link href="styles/general.css" rel="stylesheet" type="text/css" />
    <link href="styles/main.css" rel="stylesheet" type="text/css" />
    <!--<link href="ajaxfileupload.css" type="text/css" rel="stylesheet">-->
    <script type="text/javascript" src="Excel/jquery.js"></script>
    <script type="text/javascript" src="Excel/ajaxfileupload.js"></script>
    <script type="text/javascript">
    function ajaxFileUpload()
    {
    var f_content = form.fileToUpload.value; 
    var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length) 
    fileext=fileext.toLowerCase() 
    if(fileext == '')
    {
    alert('先选择文件');
    return false;
    }
    if (fileext!='.csv') 

     alert("导入的文件,必须csv格式,重新选择!");    
     return false; 
    }
    $("#loading")
    .ajaxStart(function(){
    $(this).show();
    })
    .ajaxComplete(function(){
    $(this).hide();
    }); $.ajaxFileUpload
    (
    {
    url:'buy_clothes_day_insert.php',
    secureuri:false,
    fileElementId:'fileToUpload',
    dataType: 'json',
    data:{name:'logan', id:'id'},
    success: function (data, status)
    {
    if(typeof(data.error) != 'undefined')
    {
    /*
    if(data.error != '')
    {
    alert(data.error);
    }
    else
    {
    alert(data.msg);
    }*/
    //50条插入完 if(data.msg == 1)
    {
    repeat_do_ajax();
    }else if(data.msg == 2){
    alert('无数据');
    } }
    },
    error: function (data, status, e)
    {
    //第一次post失败
    alert(e);
    }
    }
    )
    return false;
    }

    function repeat_do_ajax()
    {
    $.ajax({
    //url:"doajaxfileupload.php",
    url:"buy_clothes_day_insert.php",
    type:"GET",
    dataType: 'json',
    data:{act:'input'},
    success:function(data, status)
    {
    //还有数组重复ajax
    if(data.msg == 1){
    //setInterval(repeat_do_ajax,1000);
    repeat_do_ajax();
    }else if(data.msg == 0){
    alert('成功导入本次所有数据!');
    }

    },
    error:function(data, status)
    {
    //防止数据库超时30后在继续
    if(status == 'parsererror' || data.error == 'undefined')
    repeat_do_ajax();
    //setInterval(repeat_do_ajax,3000);
    }
    })

    }</script>
    </head>
    <body>
    <div id="wrapper">
        <div id="content">
         <h2>导入程序</h2>
             
    <img id="loading" src="Excel/loading.gif" style="display:none;">
    <form name="form" action="" method="POST" enctype="multipart/form-data">

    <table cellpadding="0" cellspacing="0" class="tableForm" height="80">
    <thead>
    <tr>
    <th>选择csv文件</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td><input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input"></td>
    </tr>
    </tbody>
    <tfoot>
    <tr>
    <td><button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">执行</button></td>
    </tr>
    </tfoot>
    </table>

    </form>    
        </div>
    </div>    
    </body>
    </html>
    php<?php
    /*do ajax */
    date_default_timezone_set('Asia/Shanghai');
    //第二次GET ajax请求 直接重复导入
    if($_REQUEST['act'] == 'input')
    {
    return_show('0',check_data());
    }
    $error = "";
    $msg = "";
    $fileElementName = 'fileToUpload';
    if(!empty($_FILES[$fileElementName]['error']))
    {
    switch($_FILES[$fileElementName]['error'])
    { case '1':
    $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
    break;
    case '2':
    $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
    break;
    case '3':
    $error = 'The uploaded file was only partially uploaded';
    break;
    case '4':
    $error = 'No file was uploaded.';
    break; case '6':
    $error = 'Missing a temporary folder';
    break;
    case '7':
    $error = 'Failed to write file to disk';
    break;
    case '8':
    $error = 'File upload stopped by extension';
    break;
    case '999':
    default:
    $error = 'No error code avaiable';
    }
    }elseif(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')
    {
    $error = 'No file was uploaded..';
    }else 
    {
    $msg .= " File Name: " . $_FILES['fileToUpload']['name'] . ", ";
    $msg .= " File Size: " . @filesize($_FILES['fileToUpload']['tmp_name']);
    //删除临时文件
    //@unlink($_FILES['fileToUpload']);
    read_csv($_FILES['fileToUpload']['tmp_name']);
    } /*读取*/
    function read_csv($filename)
    {
    $row = array();
    $key = 0;
    setlocale(LC_ALL,array('zh_CN.gbk','zh_CN.gb2312','en_US.utf8'));
    $handle=fopen($filename,'r');
    //$a = _fgetcsv($handle,1000,',','"');
    while(!feof($handle) && $data=fgetcsv($handle,1000,','))
    {
    $num = count($data);
    for($i = 0; $i < $num; $i++)

    //if(!empty($data[$i]))
    $row[$key][$i] = iconv('GBK','utf-8',trim($data[$i]));

    $key++; 
    }
    fclose($handle); if(empty($row))
    {
    return_show(2,2);
    }else{
                             //作insert
    $num = del_incomplete($row);
    //echo "<script>alert('Sucessed Input orderNum ".$num." !');</script>";

    }

    } ?>
      

  2.   

    执行了js方法外面的alert可以弹 刚看到有个js undefined 以为大小写呢 还没找到问题
      

  3.   

    凭借我多年的经验判断...应该是JS问题.
    你2个平台浏览器是否一致..浏览器是否一样.
    var f_content = form.fileToUpload.value; 
    form能直接用?我感觉这种简写出的问题 然后 在看 是JS问题 还是PHP问题..
    取消JS判断 试试可否上传成功.ajax触发处alert(1) ajax执行成功返回处alert(2)
      

  4.   

    单独来完成测试:
    1、判断js获取表单对象是否成功;
    2、判断提交结果的反馈,比如表单中不提交文件,只POST数据,判断PHP后端的POST全局数组的输出;
    3、使用去掉JS之后的表单提交,看是否成功;
    4、使用去掉JS之后的文件上传,看是否成功;(确保linux服务器上对应的目录有写权限)
      

  5.   


    这个var f_content = form.fileToUpload.value; 改了
    现在还报错是:Uncaught SyntaxError: Unexpected end of input
    chrome ie 都有...
      

  6.   

    解决了 因为返回json类型 不会返回具体错误 所以js改jquery取值后是没问题 (win下本来就没问题的),查到最后是因为运维的没建立对应表插不进报错。建表后一切正常了, 谢谢大家~~