I'm trying to create a form in which a user can upload an image with a title and description. All works fine except the image that isn't being moved to my server. Can anyone tell me what I'm doing wrong here? The folder which I'm trying to upload to has permissions set to 777.
The PHP code:
<?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('','','');
}
?>
The form:
<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>
You PHP code is broken:
<?php
}
There is a mistake in your file, it start with a }
You have unwanted }
at first line
Are you sure that the location is correct?
Try adding $_SERVER['DOCUMENT_ROOT']
in front of dir.. for example:
$image_dir = $_SERVER['DOCUMENT_ROOT']."/gfx/".$_FILES["image"]["name"];