//循环排除替换文件名中的非法字符
$errorchar=array ("-"," ","~","!","@","#","$","%","^","&","(",")","+",","," (",")","?","!","《","》",":",";","——");
foreach($errorchar as $char)
{
    if(strpos($upload_file,$char)){
        $upload_file=str_replace($char,"_",$upload_file);
    }
}

解决方案 »

  1.   

    你好,我还想问一下,在swfupload这个插件里,是怎么对文件名进行转义的?因为我用这个插件,上传文件名包含%后,在js里直接报了文件名格式不正确的错误,没有经过后台!非常感谢你!
      

  2.   

    只要文件名符合操作系统的约定,swfupload 就不会报错
    其实若不符合规则的文件名也不可能存在
      

  3.   

    我引入的是swfupload这个插件,包含%的文件名会提示文件名格式不正确?这是什么原因呢?
      

  4.   

    看下这个文件swfupload.js
    对非法字符,应该进行过滤了。
      

  5.   

    Uncaught URIError: URI malformed
    这个错误的提示信息;
      

  6.   

    URI的格式不正确
    贴出你的代码吧
    文件上传与其他表达控件不一样,文本域都是只读的,无法干预
      

  7.   

    <!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" />
    <link rel="stylesheet" type="text/css" href="/static/css/frame_top.css?v=<{$HASH}>" />
    <link rel="stylesheet" type="text/css" href="/static/css/frmUI.css?v=<{$HASH}>" />
    <link rel="stylesheet" type="text/css" href="/static/css/layout.css?v=<{$HASH}>" />
    <link rel="stylesheet" type="text/css" href="/static/css/flowUI.css?v=<{$HASH}>" />
    <script type="text/javascript" src="/static/js/jquery.js?v=<{$HASH}>"></script>
    <script type="text/javascript" src="/static/js/base.js?v=<{$HASH}>"></script>
    </head>
    <body>
    <div style="height:290px;">
    <div class="tool-bar" style="height:48px">
            可以选择多个文件一起上传
            <a class="" >
                <span id="js_shop_upload_btn"></span>
            </a>
    </div>
    <div id="main" style="top:38px;width:550px;height:232px;" class="tb-tablegrid mt-1 over-x">
         <table class="list-table" id="js_list_table" border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr rel="title_table" class="tb-tablegrid-title ">
                <td width="50%">文件名</td>
                <td width="10%">大小</td>
                <td width="15%">进度</td>
                
            </tr>
            <tbody id="js_upload_box"></tbody>
            
        </table>
    </div>
    </div>
    <input type="hidden" value="<{ $data.path }>" id="cur_id" />
    <script type="text/javascript" src="/static/js/home.base.js?v=<{$HASH}>"></script>
    <script type="text/javascript" src="/static/js/swfup_min.js?v=<{$HASH}>"></script>
    <script type="text/javascript">
    var fid= $("#cur_id").val();
    if(!fid) fid= '';
    function reloadPage()
    {
        tabinit();
        (r = parent.document.getElementById(FK.CONFIG.Frame).contentWindow);// && r.location.reload();
    }
    var UPLOAD_CONFIGS = eval('({"upload_size_limit":5250002,"upload_type_limit":["doc","docx","xls","pdf","ppt","wps","dps","et","txt","rtf","xlsx",".xlsm","xltx","xltm","xlam","xlsb","odt","gif","jpg","png","jpeg","tif","rar","zip"],"upload_temp":"<tr ><td>%2</td><td>%3</td><td><i rel=\'process\'></i></tr>","callback":reloadPage,"cid":<{$data.cid}>,"uid":<{ $data.uid}>,"upload_url":"/userdisk/attachUpload?path=<{$data.path}> ",button_text:"添加文件"})');
    FK.Upload.show(UPLOAD_CONFIGS);
    $('#popup_ok,#popup_cancel', parent.document).bind('click',function(){
        parent.jClose();
    });function tabinit(){ $("table tr").hover(function(){$(this).addClass("trhover");},function(){$(this).removeClass("trhover");}); $("table tr:even").addClass("erow"); };
     </script>
    </body>
    </html>
      

  8.   

    这个是前台页面代码,另外我用的是swfup_min.js这个插件!