在给公司做一个 DIZCUZ 的插件  有一个上传文件的功能。
现在是用  http://zmzkkk.vicp.net:84/plugin.php?id=ent:ent 这个地址上传的时候,move_uploaded_file 是不成功, 但是用这个地址  http://zmzkkk.vicp.net:84/source/plugin/ent/ent.inc.php 是可以成功,一样的代码,上传的那段代码,我看了又看, 甚至直接从 W3CSHOOL 复制过来的。 就是不知道为什么两个地址一样的代码,一个能行一个不能行, 关键是我以前也做过DISCUZ 插件里有上传的功能,都很正常,这表示,DISCUZ 里面上传应该没有什么特殊处理过吧。昨天从怀疑代码到怀疑服务器的配制,都试了好多,网上找了好多, 就是坑爹的不行·!ent.inc.php  文件 的代码
<?php
//phpinfo();
// mod文件只能被入口文件引用,不能直接访问
if(!defined('IN_DISCUZ')) {
//exit('Access Denied');
}// 游客不能//print_r($_G);
$usergroup = $_G['cache']['plugin']['et']['usergroup']; if(!$_G['uid']) {
//showmessage('抱歉,您尚未登录,无法进行此操作', '', array(), array('login' => 1));
}else if($_G['member']['extgroupids']!=$usergroup){
//showmessage('抱歉,您不属于该用户组,无法进行此操作', '', array(), array('login' => 1));
}
//$users = getuserbyuid($_G['uid']);
//print_r($users);if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      if(move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"])){
       //echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
echo '上传成功';
  }
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  
  
  //include template('et:index');?><form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

解决方案 »

  1.   

    文件上传了不能move还是根本没有上传,要分清楚
      

  2.   


    应该是不能move   $_FILES['file']['error']  是0
      

  3.   

    你的表单有 action="",也就是说是提交到本页
    那么对于  http://zmzkkk.vicp.net:84/plugin.php?id=ent:ent 的 plugin.php 是如何转向 ent.inc.php 文件的?
      

  4.   


    两个路径都是指向同一个文件, 只是?id=ent:ent  是通过 DISCUZ 的插件机制来访问,另一个是直接访问。
    再一个, 我相问一下, 我写的代码是不是很乱。 不工整,等,看起来很费眼!
      

  5.   

    如果你能确认程序文件确实被进入了
    那么就要考虑 upload/ 了
    这个相对路径究竟是相对谁的?
      

  6.   

    upload  我改成绝对路径了, 也是不行,  之前我也有试过在网站根目录和程序文件的同级目录都建了一个 UPLOAD 文件夹也是不行。
    <?php
    //phpinfo();
    // mod文件只能被入口文件引用,不能直接访问
    if(!defined('IN_DISCUZ')) {
    //exit('Access Denied');
    }// 游客不能//print_r($_G);
    $usergroup = $_G['cache']['plugin']['et']['usergroup'];if(!$_G['uid']) {
    //showmessage('抱歉,您尚未登录,无法进行此操作', '', array(), array('login' => 1));
    }else if($_G['member']['extgroupids']!=$usergroup){
    //showmessage('抱歉,您不属于该用户组,无法进行此操作', '', array(), array('login' => 1));
    }
    //$users = getuserbyuid($_G['uid']);
    //print_r($users);if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 20000))
    {
    if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
    if(move_uploaded_file($_FILES["file"]["tmp_name"],
    "E:/web/webdoce/luolaoshi.com/upload/" . $_FILES["file"]["name"])){
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    //include template('et:index');?><form action="" method="post"
    enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" /> 
    <br />
    <input type="submit" name="submit" value="Submit" />
    </form>
      

  7.   

    upload文件夹权限的问题?先改成777试试,然后再降低权限
      

  8.   

    move_uploaded_file 失败的时候会有警告信息
    先 error_reporting(E_ALL);
    看一下
      

  9.   

    一直看会员中心里, 没有提示有人回复, 没想到那里的提示有延迟, 不知道已经有人回复了
    error_reporting   我贴的代码里没有,但之前我有尝过的, 我刚才自己再加error_reporting(E_ALL); 上去试的时候,没有任何警告,  还是不成功,纠结,难道要跟一下DISCUZ 代码,可是没时间,这个插件急的很
      

  10.   

    除了error_reporting(E_ALL); 外,还需要打开错误提示 ini_set('display_errors', 1);
    另外如不确定,可以自己制造一个错误测试一下。
    个人经验,上传文件的很多问题都出自配置或权限