2013-04-14 67 views
0

我正試圖創建一個表單,用戶可以在其中上傳帶有標題和說明的圖像。除了沒有被移動到我的服務器的圖像,所有工作都很好。任何人都可以告訴我我在這裏做錯了什麼?我試着上傳文件夾到了權限設置爲777。PHP圖像上傳不起作用

的PHP代碼:

<?php 
} 

session_start(); 
if(!session_is_registered(myusername)) 
{ 
    header("location:login.php"); 
} 

// connect to the database 
$conn=mysql_connect(*censored*) or die("Kan geen verbinding maken met de DB server"); 
mysql_select_db("frankkluytmans_",$conn) or die("Kan database niet selecteren"); 

// check if the form has been submitted. If it has, start to process the form and save it to the database 
if (isset($_POST['submit'])) 
{ 
    // get form data, making sure it is valid 
    $pagid = mysql_real_escape_string(htmlspecialchars($_POST['pagid'])); 
    $titlename = mysql_real_escape_string(htmlspecialchars($_POST['title'])); 
    $contentname = mysql_real_escape_string(htmlspecialchars($_POST['contentedit'])); 
    $image = mysql_real_escape_string(htmlspecialchars("/gfx/".$_FILES["image"]["name"])); 

    // check to make sure both fields are entered 
    if ($titlename == '' || $pagid == '') 
    { 
     // generate error message 
     $error = 'ERROR: Please fill in all required fields!'; 

     // if either field is blank, display the form again 
     renderForm($pagid, $titlename, $contentname, $error); 
    } 
    else 
    { 
     if (move_uploaded_file($_FILES["image"]["tmp_name"],  "/gfx/".$_FILES["image"] ["name"])) 
     { 
      // save the data to the database 
      mysql_query("INSERT frankkluytmans SET pagid='$pagid', title='$titlename',  content='$contentname', image='$image'") or die(mysql_error()); 

      // once saved, redirect back to the view page 
      header("Location: index.php"); 
     } 
    } 
} 
else 
// if the form hasn't been submitted, display the form 
{ 
    renderForm('','',''); 
} 
?> 

形式:

<form action="" method="post" enctype="multipart/form-data"> 
     <h2> 
      <span>NEW</span> 
      <input type="text" name="pagid" value="" /> 
     </h2> 
     <div class="pages-content"> 
     <strong>Title: *</strong> <input type="text" name="title" /><br/> 
     <strong>Content: *</strong> <textarea name="contentedit"</textarea><br/> 
     <input type="file" name="image" id="image" /> 
     <input type="submit" name="submit" value="Submit"> 
     </div> 
     <script> 
      window.onload = function() { 
       CKEDITOR.replace('contentedit'); 
       console.log("editor werkt"); 
      }; 
     </script> 
</form> 
+0

爲什麼會出現在4位'[ 「形象」]'和'中[ 「名稱」]''你if(move_uploaded_file($ _ FILES [「image」] [「tmp_name」],「/gfx/".$_FILES["image」] [「name」]))' – Sean

+0

}關閉腳本前面的if語句 –

回答

0

你的PHP代碼被打破:

<?php 
} 
0

您的文件存在錯誤,它以}

0
  1. 你必須要在第一線不需要}

  2. 確定該位置是否正確?

嘗試在目錄前添加$_SERVER['DOCUMENT_ROOT'] ..例如:

$image_dir = $_SERVER['DOCUMENT_ROOT']."/gfx/".$_FILES["image"]["name"];