客户端是java应用程序,服务器端是php脚本程序。 java应用程序通过http协议上传文件,我php怎样才能接到呢?还是用 $_FILES吗? 或者是  _GET ,_POST ? 

解决方案 »

  1.   

    $_FILES 
    经由 HTTP POST 文件上传而提交至脚本的变量。类似于旧数组 $HTTP_POST_FILES 数组(依然有效,但反对使用)。详细信息请参阅 POST 方法上传。 
      

  2.   

    $_FILES
    只要是http傳的都用這個
      

  3.   

    前端 JS里你自己随便写吧,可以限制上传的类型的
    <html>
    <head>
    <script>
    var $=function(s){return(typeof s=="object")?s:document.getElementById(s);};
    function ck(obj)
    {
    if(obj.value.length>0){
    var af="zip";
    if (window.navigator.userAgent.indexOf("MSIE")>=1)
    {
    if(eval("with(obj.value)if(!/"+af.split(",")+"/ig.test(substring(lastIndexOf('.')+1,length)))1;")){alert("上传的文件类型只能为:\n"+af);
    obj.createTextRange().execCommand('delete')};
    }else if(window.navigator.userAgent.indexOf("Firefox")>=1){
    if(eval("with(obj.value)if(!/"+af.split(",")+"/ig.test(substring(lastIndexOf('.')+1,length)))1;")){
    alert("上传的文件类型只能为:\n"+af);
    Upload.clear("path");
    return false;
    }
    }
    }
    }

    function ts(){
    var obj = $("path");
    if(obj.value==""){
    alert('请您上传更新文件');
    return false;
    }
    }

    var Upload = { 
       clear: function(id){ 
         var up = (typeof id=="string")?document.getElementById(id):id; 
         if (typeof up != "object") return null; 
         var tt = document.createElement("span"); 
         tt.id = "__tt__"; 
         up.parentNode.insertBefore(tt,up); 
         var tf = document.createElement("form"); 
         tf.appendChild(up); 
         document.getElementsByTagName("body")[0].appendChild(tf); 
         tf.reset(); 
         tt.parentNode.insertBefore(up,tt); 
         tt.parentNode.removeChild(tt); 
         tt = null; 
         tf.parentNode.removeChild(tf); 
       }
      }
    </script>
    <script language="JavaScript" src="js/popcalendar.js" type="text/javascript"></script>
    <title>上传ZIP</title>
    </head>
    <body>
    <form name="fileupload" action="dispose.php" method="post" enctype="multipart/form-data" onsubmit="return ts();">
    <input type="file" name="path" id="path" onchange="ck(this)"/><input name="submit" type="submit" value="上传" />
    </form>
    <?php
    $ds = date('Y-m-d')." 00:00:00";
      $es = date('Y-m-d')." 23:00:00";
      echo '<br><table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98" >';
      echo "<tr align='left'>\n";
      echo '<td height="18" bgcolor="#FFFFFF" class="STYLE2"><div align="left" class="STYLE2 STYLE1">';
      echo "<br>选择要查看的时间";
      echo "<br><hr><form name='form1' method='get' action='search_log.php' />\n";
      echo "&nbsp;&nbsp;<input type='text' name='DATETIME_s1' value='$ds' size='19' class='butt' readonly=''/>&nbsp;&nbsp;至&nbsp;&nbsp;<input type='text' name='DATETIME_e1' size='19' value='$es' class='butt' readonly=''/>&nbsp;&nbsp;<input type='submit' name='Submit' value='Search'/><br>\n";
      echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
      echo "<input name='按钮' type='button' style='font-size:11px' onClick=\"popUpCalendar(this, form1.DATETIME_s1, 'yyyy-mm-dd',0,' ',1)\" value='选择开始日期'>\n";
      echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
      echo "<input name='按钮' type='button' style='font-size:11px' onClick=\"popUpCalendar(this, form1.DATETIME_e1, 'yyyy-mm-dd',23,' ',1)\" value='选择截至日期'>\n";
     
      //echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='确定' name='handin'/>";
     //----------------------------------------------------------------
      echo "</form>\n";
      echo "</div></td>";
      echo "</tr>\n";
      echo "</table>\n"; 
    ?> 
    </body>
    </html>后端if($filetype=="application/x-zip-compressed"||$filetype=="application/zip"){
    if ($_FILES["path"]["error"] > 0)
    {
    echo "<script>alert('Return Code: " . $_FILES["path"]["error"] .",文件路径错误,请您重新上传')location.href='fileupload.php';</script>";
    }
    else
    {
    if (file_exists($filename))
    {
    echo "<script>alert('exists".$filename.",文件存在,请您重新上传');location.href='fileupload.php';</script>";
    }
    else
    {
    if (is_uploaded_file($filetmpname)) {
    move_uploaded_file($filetmpname, $filename);
    if(! unzip($filename,$uploaddir)){
    echo "<script>alert('ErrorUpload,解压ZIP失败,请您重新上传');location.href='fileupload.php';</script>";
    exec("rm -f -r ".$uploaddir);
    }
    unlink($filename);
                     }
     }
      

  4.   

    通过url,使用超全局变量$_POST。