0

我在这里遇到情况,我的想法不多了,当我上传 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>

非常感谢您的帮助

4

1 回答 1

1

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"];
}
于 2012-07-31T09:30:04.413 回答