2012-07-31 29 views
0

我在這裏有情況,我用盡想法,當我上傳2圖像只有一個圖像保存在文件夾中。任何人都可以幫助我的腳本?我有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> 

非常感謝您的幫助

回答

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"]; 
} 
+0

你得到任何錯誤訊息?你可以嘗試回顯'$ file1',看看你是否得到一個文件名? – asprin 2012-07-31 09:42:10

+0

我已經嘗試過,但無法正常工作。結果仍然是一樣的,只有一個圖像保存在文件夾 – 2012-07-31 09:42:38

+0

沒有錯誤,文件名工作正常,並已在數據庫中插入, – 2012-07-31 09:45:22

相關問題