可能重复:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error
我又回来了,还在学习多重上传。好的,我在这里遇到了一个情况。我得到了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>
我希望这更容易被发现。非常感谢您的帮助
答案 0 :(得分: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 here
move_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
}
}
答案 1 :(得分: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