0

可能重复:
警告:mysql_fetch_* 期望参数 1 是资源,布尔给定错误

我又回来了,还在学习多重上传。好的,我在这里遇到了情况。我收到了 2 个警告:

警告:move_uploaded_file() 期望参数 1 为字符串,数组在第 32 行的 F:\wamp\www\dki\1\entry_fotos.php 中给出

警告:move_uploaded_file() 期望参数 1 为字符串,数组在第 45 行的 F:\wamp\www\dki\1\entry_fotos.php 中给出

这是代码

   $ne_photo_images = $_FILES['ne_photo_image']['name'];
   $fe_photo_images = $_FILES['fe_photo_image']['name'];
   $tmp_file = $_FILES['ne_photo_image']['tmp_name'];
   $tmp_file1 = $_FILES['fe_photo_image']['tmp_name'];

      if(!is_array($ne_photo_images)) {
         $ne_photo_images = array();

    }

  if(!is_array($tmp_file)) {
        $tmp_file = array();
     }
       if(! move_uploaded_file($tmp_file, 'image/' . $ne_photo_images))

 if(!is_array($fe_photo_images)) {
        $fe_photo_images = array();
    }
 if(!is_array($tmp_file1)) {
        $tmp_file1 = array();
    }
    if(! move_uploaded_file($tmp_file1, 'image/' . $fe_photo_images))

我之前从我的问题反馈中得到了这个查询代码

   $sql = "INSERT INTO photo(`photo_id`, `ne_photo_image`, `fe_photo_image`, `hop_id`,    `title`) VALUES";
   for($i = 0, $l = sizeof($titles) ; $i < $l ; $i++)
   {
      //adding row datas
      $sql .= " (null, 
                 '".$ne_photo_images [$i]."', 
                 '".$fe_photo_images [$i]."', 
                 '".$hopid."', 
                 '".$titles[$i]."')";
      if($i < $l - 1)
         $sql .= ",";
   }

   if(mysql_query($sql))
   {         
   }

这是我的表格:

<form method="post" enctype="multipart/form-data">
    <table border="0"cellpadding="0" cellspacing="0" width= "100%">
        <tr>
            <td>Hop Name :<?echo "$data[hop_name]"?>
                <input type='hidden' name='photo_hop_id' value='<?echo"$data[hop_id]"?>'>
            </td>
        </tr>
                <table border="0"cellpadding="0" cellspacing="0" width= "100%">
    <tr>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    Near End Site Name : <?echo "$data[ne_site_name]"?>
                        </br>
                    Near End Site Id : <?echo "$data[ne_site_code]"?>
                </td>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    Far End Site Name : <?echo "$data[fe_site_name]"?>
                        </br>
                    Far End Site Id : <?echo "$data[fe_site_code]"?>
                </td>
    </tr>   
    <tr>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <?  $pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 1");
                        $dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]"?> 
                    <input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :  
                    <input type="file" name="ne_photo_image[]">
                </td>
                <td cellpadding="0" cellspacing="0" width= "50%"> 
                    <?echo "$dpm1[0]"?> : <input type="file" name="fe_photo_image[]">
                </td>
    </tr>   

</table>

    </table>
    <input type="submit" value="tambah" />
</form>

我希望这更容易发现。非常感谢您的帮助

4

2 回答 2

0

这是最终的代码

    $hopid = $_POST['photo_hop_id'];
$titles = $_POST['photo_name_id'];

$ne_photo_images = $_FILES[ne_photo_image][name];
$fe_photo_images = $_FILES[fe_photo_image][name];

while(list($key,$value) = each($_FILES['ne_photo_image']['name']))
    {
        if(!empty($value))
        {
            $filename = $value;
                $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

                $add = "image/$filename";
                   //echo $_FILES['images']['type'][$key];
             // echo "<br>";
                copy($_FILES['ne_photo_image']['tmp_name'][$key], $add);
                chmod("$add",0777);


        }
    }
         while(list($key,$value) = each($_FILES['fe_photo_image']['name']))
    {
        if(!empty($value))
        {
            $filename = $value;
                $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

                $add = "image/$filename";
                   //echo $_FILES['images']['type'][$key];
             // echo "<br>";
                copy($_FILES['fe_photo_image']['tmp_name'][$key], $add);
                chmod("$add",0777);


        }
    }

              $sql = "INSERT INTO photo(`photo_id`, `ne_photo_image`, `fe_photo_image`, `hop_id`,    `title`) VALUES";
   for($i = 0, $l = sizeof($titles) ; $i < $l ; $i++)
   {
      //adding row datas
      $sql .= " (null, 
                 '".$ne_photo_images [$i]."', 
                 '".$fe_photo_images [$i]."', 
                 '".$hopid."', 
                 '".$titles[$i]."')";
      if($i < $l - 1)
         $sql .= ",";
   }

   if(mysql_query($sql))
   {         
   }

   else
于 2012-08-02T18:07:24.357 回答
0

这导致你的问题......

if(!is_array($ne_photo_images)) { $ne_photo_images = array(); }
if(!is_array($tmp_file)) { $tmp_file = array(); } 

如果您的 $ne_photo_images 不是一个数组,您可以将其更改为一个空数组,但您的 $tmp_file 也是如此。然后将 $tmp_file 作为参数提供给 move_uploaded_file 和 $ne_photo_images,它们只移动一个文件。不是文件数组

enter code heremove_uploaded_file($tmp_file, 'image/' . $ne_photo_images))

你应该做这样的事情

$ne_photo_images[] = $_FILES['ne_photo_image']['name'];
$ne_photo_images[] = $_FILES['fe_photo_image']['name'];
$tmp_file[] = $_FILES['ne_photo_image']['tmp_name'];
$tmp_file[] = $_FILES['fe_photo_image']['tmp_name'];   

然后做类似的事情

$allGood = true;
for($i = 0; $i < count($ne_photo_images); $i++)
{
  if (!move_uploaded_file($tmp_file[$i], 'image/' . $ne_photo_images[$i]))
  {
    $allGood = false;
  }
}

if (!$allGood) { die("Not all files where moved."); }

更通用的解决方案

foreach ($_FILES as $file)
{
  if (move_uploaded_files($file['tmp_name'], 'image/' . $file['name']))
  {
    // also insert the file into the database here

  }
}
于 2012-08-02T08:41:39.477 回答