我正在尝试创建一个表单,用户可以在其中上传带有标题和描述的图像。除了没有移动到我的服务器的图像外,一切正常。谁能告诉我我在这里做错了什么?我尝试上传到的文件夹的权限设置为 777。
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>