2012-09-16 192 views
1

我盯着做我自己的配置文件系統,用戶可以存儲用戶名,密碼,名字,姓氏,年齡和個人資料圖片。上傳系統問題到服務器

通過此過程上載圖像時出現問題。代碼出現錯誤,我不明白爲什麼。爲英文道歉,我是來自丹麥(注:從編輯意譯)

這裏是我的代碼

<?php 
    include ("inc/db/db.php"); 
    if (isset($_POST["godkendt_bruger"])) 
    { 
     $query = 'SELECT NULL FROM `bruger` WHERE `brugernavn` = ?'; 
     if ($stmt = $mysqli->prepare($query)) 
     { 
      $stmt->bind_param('s', $brugernavn); 
      $brugernavn = $_POST["brugernavn"]; 
      $stmt->execute(); 
      $stmt->store_result(); 
      $count = $stmt->num_rows; 
      $stmt->close(); 

      if ($count > 0) 
      { 
       $user_found = 1; 
      } 
     } 

     if (!isset($user_found)) 
     { 
      if ($_POST["pass"] != $_POST["gentag"]) 
      { 
       $errors = 1; 
       echo "<li id=\"check_not\">Angive ens password på siden..</li>"; 
      } 

      if (empty($_POST["pass"]) && empty($_POST["gentag"])) 
      { 
       $errors = 1; 
       echo "<li id=\"check_not\">Angive et password på siden..</li>"; 
      } 

      if (empty($_POST["navn"])) 
      { 
       $errors = 1; 
       echo "<li id=\"check_not\">Angive et Fornavn</li>"; 
      } 

      if (empty($_POST["efternavn"])) 
      { 
       $errors = 1; 
       echo "<li id=\"check_not\">Angive et Efternavn</li>"; 
      } 

      if (!isset($errors)) 
      { 
       $pb = null; 
       include "inc/img/class.upload.php"; 
       $handle = new Upload($_FILES["file"]); 

       if ($handle->uploaded) 
       { 
        //lidt mere store billeder 
        $handle->image_resize = true; 
        $handle->image_ratio_y = true; 
        $handle->image_x = 220; 
        $handle->Process("profil/store"); 

        //til profil billede lign.. 
        $handle->image_resize = true; 
        $handle->image_ratio_crop = true; 
        $handle->image_y = 115; 
        $handle->image_x = 100; 
        $handle->Process("profil"); 

        //til profil billede lign.. 
        $handle->image_resize = true; 
        $handle->image_ratio_crop = true; 
        $handle->image_y = 75; 
        $handle->image_x = 75; 
        $handle->Process("profil/lille"); 
        $pb = $handle->file_dst_name; 
       } 
       else 
       { 
        echo 'Der opstod en fejl i erklæringen: - upload ' . $mysqli->error; 
       } 
      } 

      //Lukker $errors 
      if (!isset($user_found)) 
      { 
       $query = 'INSERT INTO `bruger` ' 
         . '(`Brugernavn`, `password`, `profilbillede`, ' 
         . '`navn`, `efternavn`, `alder`) ' 
         . 'VALUES (?, ?, ?, ?, ?, ?)'; 
       if ($stmt = $mysqli->prepare($query)) 
       { 

       $stmt->bind_param(
        'sssssi', 
        $brugernavn, 
        $password, 
        $profilbillede, 
        $navn, 
        $efternavn, 
        $alder 
       ); 

       $brugernavn = $_POST["brugernavn"]; 
       $password  = $_POST["pass"]; 
       $profilbillede = $pb; 
       $navn   = $_POST["navn"]; 
       $efternavn  = $_POST["efternavn"]; 
       $alder   = $_POST["alder"]; 

       $stmt->execute(); 
       $stmt->close(); 

      } 
      else 
      { 
       /* Der er opstået en fejl */ 
       echo 'Der opstod en fejl i erklæringen til ligge i databasen: ' . $mysqli->error; 
      } 
     } 
    } 
    else 
    { 
     echo "<li id=\"check_not\">Dette brugernavn er optaget!!</li>"; 
    } 
} 
else 
{ 
    echo "<li id=\"check_opret\">Indtast dine oplysninger herunder for at opret en bruger </a></li>"; 
} 

?> 

它出現的錯誤是在此塊

if ($handle->uploaded) 
{ 
    //lidt mere store billeder 
    $handle->image_resize = true; 
    $handle->image_ratio_y = true; 
    $handle->image_x = 220; 
    $handle->Process("profil/store"); 

    //til profil billede lign.. 
    $handle->image_resize = true; 
    $handle->image_ratio_crop = true; 
    $handle->image_y = 115; 
    $handle->image_x = 100; 
    $handle->Process("profil"); 

    //til profil billede lign.. 
    $handle->image_resize = true; 
    $handle->image_ratio_crop = true; 
    $handle->image_y = 75; 
    $handle->image_x = 75; 
    $handle->Process("profil/lille"); 
    $pb = $handle->file_dst_name; 

} 
else 
{ 
    echo 'Der opstod en fejl i erklæringen: - upload ' . $mysqli->error; 
} 

錯誤是:Der opstod en fejl ierklæringen: - upload聲明中有錯誤),沒有別的。數據不存儲在數據庫中。

This my html her;

<form name="opret_bruger" method="post" action="#" enctype="multipart/form-data"> 
<tr> 
    <td><p>Brugernavn</p></td> 
    <td><input type="text" name="brugernavn"></td> 
</tr> 
<tr> 
    <td><p>Password</p></td> 
    <td><input type="password" name="pass"></td> 
</tr> 
<tr> 
    <td><p>Password gentag</p></td> 
    <td><input type="password" name="gentag"></td> 
</tr> 
<tr> 
    <td><p>Fornavn</p></td> 
    <td><input type="text" name="navn"></td> 
</tr> 
<tr> 
    <td><p>Efternavn</p></td> 
    <td><input type="text" name="efternavn"></td> 
</tr> 
    <tr> 
    <td><p>Alder</p></td> 
    <td> 
     <select name="alder_1"> 
    <?php 
    if ($stmt = $mysqli->prepare('SELECT `alder` FROM `alder`')) { 
     $stmt->execute(); 

     /* Bind resultatet */ 
     $stmt->bind_result($alder); 

     /* Hent rækker og udskriv data */ 
     while ($stmt->fetch()) { 
     ?> 
      <option><?php echo $alder;?></option> 
     <?php 
     } 

      /* Luk statement */ 
      $stmt->close(); 

     } else { 
      /* Der er opstået en fejl */ 
      echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error; 
     } 
     ?> 
     </select> 
    </td> 
</tr> 
<tr> 
    <td><p>Upload Profilbillede</p></td> 
    <td><input type="file" name="profilbillede"></td> 
</tr> 
<tr> 
    <td></td> 
    <td><input type="submit" name="godkendt_bruger"></td> 
</tr> 
</form> 

如果您有任何建議,我會歡迎他們,更好地處理代碼,以便可以存儲圖像。

加斯帕 - 丹麥

回答

1

幾點建議:

檢查文件的上傳路徑。我假設

$handle->Process("profil/store"); 

是正在存儲文件的位置。如果文件沒有上傳,只需檢查文件權限即可。

此外,下面的代碼工作?我可能是錯的,但不應該在綁定之前設置參數?即

  $query = 'INSERT INTO `bruger` ' 
        . '(`Brugernavn`, `password`, `profilbillede`, ' 
        . '`navn`, `efternavn`, `alder`) ' 
        . 'VALUES (?, ?, ?, ?, ?, ?)'; 
      if ($stmt = $mysqli->prepare($query)) 
      { 

      $brugernavn = $_POST["brugernavn"]; 
      $password  = $_POST["pass"]; 
      $profilbillede = $pb; 
      $navn   = $_POST["navn"]; 
      $efternavn  = $_POST["efternavn"]; 
      $alder   = $_POST["alder"]; 

      $stmt->bind_param(
       'sssssi', 
       $brugernavn, 
       $password, 
       $profilbillede, 
       $navn, 
       $efternavn, 
       $alder 
      ); 

我希望這有助於一些。

+0

不能看到你如何看待它,我嘗試,但無法找到它適應或模仿;) –

+0

你不能嘗試適應代碼和模擬,所以它可能是我可以更好地理解它:) –

+0

ooohhh它現在的作品,並感謝您的幫助,然後!!!!再次感謝! –

0

文件上傳字段實際上命名爲profilbillede

     <td><input type="file" name="profilbillede"></td> 
                ^^^^^^^^^^^^^ 

,這意味着它會$_FILES['profilbillede'],不$_FILES['file']爲你使用它。

+0

$ handle = new Upload($ _ FILES ['profilbillede']); 所以它應該看起來像這裏? –

+0

我只是嘗試,它不起作用:( –

相關問題