我正試圖創建一個表單,用戶可以在其中上傳帶有標題和說明的圖像。除了沒有被移動到我的服務器的圖像,所有工作都很好。任何人都可以告訴我我在這裏做錯了什麼?我試着上傳文件夾到了權限設置爲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>
爲什麼會出現在4位'[ 「形象」]'和'中[ 「名稱」]''你if(move_uploaded_file($ _ FILES [「image」] [「tmp_name」],「/gfx/".$_FILES["image」] [「name」]))' – Sean
}關閉腳本前面的if語句 –