我上传了两个图像文件,但只有一个保存在文件夹中


i have 2 image file uploaded but only one save on folder

我在这里遇到了这种情况,我已经不知道了,当我上传2个图像时,文件夹中只保存了一个图像。有人能帮我写剧本吗?

$q = "SELECT h.hop_id,h.hop_name, n.ne_site_name, n.ne_site_code, f.fe_site_name, f.fe_site_code, p.photo_id, p.ne_photo_image, p.fe_photo_image
FROM hop AS h 
    LEFT JOIN ne_site AS n ON(h.ne_site_id = n.ne_site_id)
    LEFT JOIN fe_site AS f ON(h.fe_site_id = f.fe_site_id)
    LEFT JOIN photo AS p ON(h.hop_id = p.hop_id)
    WHERE h.hop_id = '".$_GET['kode']."'
    "; 
    $r = mysql_query($q) or die ($q);
    $data = mysql_fetch_array ($r);
$tmp_file = $_FILES[ne_photo_image][tmp_name];
$size = $_FILES[ne_photo_image][size];
$file = $_FILES[ne_photo_image][name];
$tmp_file1 = $_FILES[fe_photo_image][tmp_name];
$size1 = $_FILES[fe_photo_image][size];
$file1 = $_FILES[fe_photo_image][name];

            $q = mysql_query("insert into photo(ne_photo_image,fe_photo_image,title,hop_id)
        values ('$file','$file1','$_POST[photo_name_id]','$_POST[photo_hop_id]')") or die(mysql_error());
            if ($q) {
            } else {
                echo 'gagal';
            }
    move_uploaded_file($tmp_file, 'image/' . $file)

这是我的表格:

    <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>

非常感谢的帮助

您只对第一个文件使用move_uploaded_file,这就是没有上传第二个图像的原因。将另一个用于第二个图像。

move_uploaded_file($tmp_file, 'image/' . $file)
move_uploaded_file($tmp_file1, 'image/' . $file1)

UDPATE:用于调试

if(! move_uploaded_file($tmp_file1, 'image/' . $file1))
{
  echo $_FILES["fe_photo_image"]["error"];
}
相关文章: