2010-12-14 15 views
0

で持ち運びにくい名前を配置する必要があり私は正常にPHPを使用して、私の画像をアップロードして、ループが、私の問題は私のデシベルは、複数の画像をアップロードした後、私のデシベル

にアップロードされたファイルの名前を置く方法であり、これは私のコードです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Add event</title> 
<link href="../css_style.css" rel="stylesheet" type="text/css" /> 
</head> 

    <?php 
    error_reporting(E_ALL); 
    include_once "../config/config.php"; 

    if (isset($_POST['submit'])) { 

     $target = 'upload_occasion/'; 

     $title = $_POST['img_title']; 
     $des = $_POST['img_des']; 
     $putData = " insert into photos_occasion (id, title, description) values ('', '$title', '$des') "; 
     $result = $db->query($putData) or die ($db->error); 


     foreach ($_FILES["img"]["error"] as $key => $error) 
{ 
    if ($error == UPLOAD_ERR_OK) 
    { 
     $tmp_name = $_FILES["img"]["tmp_name"][$key]; 
     $name = $_FILES["img"]["name"][$key]; 
     move_uploaded_file($tmp_name, "$target/$name"); 

     $putData = " insert into photos_occasion (id, image_name) values ('', '$target/$name') "; 
     $result = $db->query($putData); 
    } 
} 

    if ($result) { 

       echo "Your event has been add successfully"; 

       }else{ 

        echo "Sorry there was an error please contact the administrator of the site"; 

        } 
     } 

    ?> 

<body> 
<div id="werpper"> 
     <div id="content"> 
      <div id="header">My control - Panel</div> 
       <div id="body_cntent"> 
        <div id="left_side"> 
         <p>Home and instructions</p> 
          <p><a href="../control_panel.php">main directory events</a></p> 
         <p>Active or unactive events</p> 
         <p><a href="includes/add_event.php">Add new event</a></p> 
         <p><a href="../control_panel.php">main directory photos</a></p> 
         <p>Add Photos </p> 
        </div> 
          <div id="right_side"> 

           <h1>Add Photos and occasion</h1> 
          <form method="post" action="" enctype="multipart/form-data"> 
           <table width="600" border="0" cellpadding="10"> 
           <tr> 
            <td>Images tiltle</td> 
            <td><input name="img_title" type="text" value="" size="50" /></td> 
           </tr> 
           <tr> 
            <td>Images Description</td> 
            <td><textarea name="img_des" rows="10" cols="50"></textarea></td> 
           </tr> 
           <tr> 
            <td>Images (max 10 img)</td> 
            <td>&nbsp;</td> 
           </tr> 
           <tr> 
            <td><label for="img1">Image 1</label></td> 
            <td><input type="file" name="img[]" /></td> 
           </tr> 
           <tr> 
            <td><label for="img2">Image 2</label></td> 
            <td><input type="file" name="img[]" id="fileField2" /></td> 
           </tr> 
           <tr> 
            <td><label for="img3">Image 3</label></td> 
            <td><input type="file" name="img[]" id="fileField3" /></td> 
           </tr> 
           <tr> 
            <td><label for="img4">Image 4</label></td> 
            <td><input type="file" name="img[]" id="fileField4" /></td> 
           </tr> 
           <tr> 
            <td><label for="img5">Image 5</label></td> 
            <td><input type="file" name="img[]" id="fileField5" /></td> 
           </tr> 
           <tr> 
            <td><label for="img6">Image 6</label></td> 
            <td><input type="file" name="img[]" id="fileField6" /></td> 
           </tr> 
           <tr> 
            <td><label for="img7">Image 7</label></td> 
            <td><input type="file" name="img[]" id="fileField7" /></td> 
           </tr> 
           <tr> 
            <td><label for="img8">Image 8</label></td> 
            <td><input type="file" name="img[]" id="fileField8" /></td> 
           </tr> 
           <tr> 
            <td><label for="img9">Image 9</label></td> 
            <td><input type="file" name="img[]" id="fileField9" /></td> 
           </tr> 
           <tr> 
            <td><label for="img10">Image 10</label></td> 
            <td><input type="file" name="img[]" id="fileField10" /></td> 
           </tr> 
           <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
           </tr> 
           <tr> 
            <td>&nbsp;</td> 
            <td><input type="submit" name="submit" value="Save" /> 
            &nbsp;&nbsp; 
            <input type="reset" name="reset" value="Empty fields" /></td> 
           </tr> 
          </table> 
          </form> 
         </div> 
       </div> 
      <div id="footer"></div> 
     </div> 
</div> 
</body> 
</html> 

1 - 私は(まだ)後で後にそれらを得ることができるので、私は私のDBに彼らの名前を置くことができない

答えて

1

問題1: あなたはおそらく$タイトルではなく、$ img_titleをしたい(と見問題2)

これを試してみてください。

<?php 
error_reporting(E_ALL); 
include_once("../config/config.php"); 

if (isset($_POST[ 'submit' ])) 
{ 
    $target = 'upload_occasion/'; 

    $title = $_POST[ 'img_title' ]; 
    $des = $_POST[ 'img_des' ]; 

    // insert occasion info 
    $putData = "INSERT INTO photos_occasion (id, title, description) values ('', '$title', '$des')"; 
    $result = $db->query($putData) or die ($db->error); 

    // NOTICE THIS LINE .. you should implement something to get the inserted id (maybe from the $result) 
    $photoOccasionID = GET_INSERTED_ID_SOMEHOW; 

    // then update occasion with each photo 
    $num = 1; 
    foreach ($_FILES[ "img" ][ "error" ] as $key => $error) 
    { 
     if ($error == UPLOAD_ERR_OK) 
     { 
      $tmp_name = $_FILES[ "img" ][ "tmp_name" ][ $key ]; 
      $name = $_FILES[ "img" ][ "name" ][ $key ]; 
      move_uploaded_file($tmp_name, "$target/$name"); 

      $putData = "UPDATE photos_occasion SET image_" . $num . " = '$target/$name' WHERE id = " . $photoOccasionID; 
      $result = $db->query($putData); 
      $num++; 
     } 
    } 

    echo "Your event has been add successfully"; 
} 
?> 

これは途中であなたを置くべきだと思います...

とにかく、サイドノートとして、私はあなたのデータベースを設計する正しい方法は似ていると思う:

テーブルの機会(ID、タイトル、説明)

テーブルphotos_occasion(ID、occasion_id、画像、順序)ここ 、occasion_idは、テーブル(idカラム) 順序を機会への外部キーである(あなたは本当に、その順序を知る必要がある場合)の写真の番号であると言うために私が持っている最初のものですMr.Diogoあなたのため

+0

私は本当にスタックオーバーフローと人々が好きです –

+0

私のループに "SQLの挿入クエリ($ putDataと$ resultとif-else)を入れる方法はまだ最後の部分を理解していません" –

+0

OK私はあなたにMr.Diogoを教えました。問題1を解決しましたが、2つの理由で今のところ基盤を知る必要があります。エラーのアップロードと画像の拡張のために残りの部分を作っていきますが、今のところ、私のデシベルにアップロードした画像 おかげで再びMr.Diogoこの –

0

おかげで、これは私のマスターからの助けを借りて入れた最後のコードです

<?php 

     error_reporting(E_ALL); 
     include_once("../config/config.php"); 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Add event</title> 
<link href="../css_style.css" rel="stylesheet" type="text/css" /> 
</head> 

    <?php 

if (isset($_POST['submit'])) 
{ 

    $target = 'upload_occasion/'; 

    $title = $_POST[ 'img_title' ]; 
    $des = $_POST[ 'img_des' ]; 

    // insert occasion info 
    $putData = "INSERT INTO photos_occasion (id, title, description) values ('', '$title', '$des')"; 
    $result = $db->query($putData) or die ($db->error); 
    $photoOccasionID=$db->insert_id; 
    // NOTICE THIS LINE .. you should implement something to get the inserted id (maybe from the $result) 


    // then update occasion with each photo 
    $num = 1; 
    foreach ($_FILES[ "img" ][ "error" ] as $key => $error) 
    { 
     if ($error == UPLOAD_ERR_OK) 
     { 
      $tmp_name = $_FILES[ "img" ][ "tmp_name" ][ $key ]; 
      $name = $_FILES[ "img" ][ "name" ][ $key ]; 
      move_uploaded_file($tmp_name, "$target/$name"); 

      $putData = "UPDATE photos_occasion SET image_" . $num . " = '$target/$name' WHERE id = " . $photoOccasionID; 
      $result = $db->query($putData); 
      $num++; 



     } 

    } 

    echo "Your event has been add successfully"; 
} 
?> 




<body> 
<div id="werpper"> 
     <div id="content"> 
      <div id="header">My control - Panel</div> 
       <div id="body_cntent"> 
        <div id="left_side"> 
         <p>Home and instructions</p> 
          <p><a href="../control_panel.php">main directory events</a>      </p> 
         <p><a href="add_event.php">Add new event</a>      </p> 
         <p><a href="add_photos_and_occasion.php"></a><a href="add_photos_and_occasion.php">Add Photos_occasion</a></p> 
        </div> 
          <div id="right_side"> 

           <h1>Add Photos and occasion</h1> 
          <form method="post" action="" enctype="multipart/form-data"> 
           <table width="600" border="0" cellpadding="10"> 
           <tr> 
            <td>Images tiltle</td> 
            <td><input name="img_title" type="text" value="" size="50" /></td> 
           </tr> 
           <tr> 
            <td>Images Description</td> 
            <td><textarea name="img_des" rows="10" cols="50"></textarea></td> 
           </tr> 
           <tr> 
            <td>Images (max 10 img)</td> 
            <td>&nbsp;</td> 
           </tr> 
           <tr> 
            <td><label for="img1">Image 1</label></td> 
            <td><input type="file" name="img[]" /></td> 
           </tr> 
           <tr> 
            <td><label for="img2">Image 2</label></td> 
            <td><input type="file" name="img[]" id="fileField2" /></td> 
           </tr> 
           <tr> 
            <td><label for="img3">Image 3</label></td> 
            <td><input type="file" name="img[]" id="fileField3" /></td> 
           </tr> 
           <tr> 
            <td><label for="img4">Image 4</label></td> 
            <td><input type="file" name="img[]" id="fileField4" /></td> 
           </tr> 
           <tr> 
            <td><label for="img5">Image 5</label></td> 
            <td><input type="file" name="img[]" id="fileField5" /></td> 
           </tr> 
           <tr> 
            <td><label for="img6">Image 6</label></td> 
            <td><input type="file" name="img[]" id="fileField6" /></td> 
           </tr> 
           <tr> 
            <td><label for="img7">Image 7</label></td> 
            <td><input type="file" name="img[]" id="fileField7" /></td> 
           </tr> 
           <tr> 
            <td><label for="img8">Image 8</label></td> 
            <td><input type="file" name="img[]" id="fileField8" /></td> 
           </tr> 
           <tr> 
            <td><label for="img9">Image 9</label></td> 
            <td><input type="file" name="img[]" id="fileField9" /></td> 
           </tr> 
           <tr> 
            <td><label for="img10">Image 10</label></td> 
            <td><input type="file" name="img[]" id="fileField10" /></td> 
           </tr> 
           <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
           </tr> 
           <tr> 
            <td>&nbsp;</td> 
            <td><input type="submit" name="submit" value="Save" /> 
            &nbsp;&nbsp; 
            <input type="reset" name="reset" value="Empty fields" /></td> 
           </tr> 
          </table> 
          </form> 
         </div> 
       </div> 
      <div id="footer"></div> 
     </div> 
</div> 
</body> 
</html> 

このコードこの問題を解決するために私は5日間座っていました。

このコードは、ユーザーが眉に彼らがしたい画像を入れても、彼らは

おかげで再びMr.Diogoをしたいし、良い夜持ってどこいずれかにそれを呼び出すことができるように、データベースに彼らに名前を入れることができます。

関連する問題