Right, well basically I'm trying to make a photoblog. I seem to have got myself a good code apart from one thing - the images don't upload.
addphoto.php
Basically what happens is when I try to upload the image and everything it comes up with the first error:
addphoto.php
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
include('dbconnect.php');
$photo = $_POST['photo'];
$title = $_POST['title'];
$description = $_POST['description'];
$comments = $_POST['comments'];
$date = addslashes(strip_tags(date("j/n/y")));
$uploadto = "/photos/";
$maxsize = 1048576;
$filename = $_FILES['photo']['name'];
$filewidth = $_FILES['photo']['width'];
$fileheight = $_FILES['photo']['height'];
$allowed = array (
"image/gif" => "gif",
"image/pjpeg" => "jpg",
"image/png" => "png",
"image/bmp" => "bmp",
"image/jpeg" => "jpg",
"image/jpg" => "jpeg",
);
if(isset($_POST['submit'])&& strlen($_POST['submit']) > 0 ) {
if(!array_key_exists($_FILES['photo']['type'], $allowed)) {
die("File is an invalid type (.gif, .jpeg, .png or .bmp).");
}
elseif(!array_key_exists($_FILES['photo']['size'] > $maxsize)) {
die("File is too big (>1MB).");
}
elseif(file_exists($uploadto . $_FILES['photo']['title'])) {
die("This file already exists.");
}
else {
copy($filename, $uploadto.$filename) or die("Error, please try again later");
$image = $uploadto.$filename;
mysql_query("INSERT * INTO photos SET title='$title', description='$description', date='$date', location='$image', comments='$comments', height='$fileheight', width='$filewidth'") or die(mysql_error());
echo "Image uploaded.<br /><a href='index.php'>Go back to the photoblog</a> or <a href='".$_SERVER['PHP_SELF']."'>Upload another photo";
}
}
else {
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
Photo Title:<br />
<input type="text" name="title" /><br />
Photo description:<br />
<textarea name="description"></textarea><br />
Comments allowed?<br />
<select name="comments">
<option>Yes</option>
<option>No</option>
</select><br />
Upload photo:<br />
<input type="file" name="photo" /><br />
<input type="submit" name="submit" value="Upload photo" />
</form>
<?php
}
?>
</body>
</html>
I can't see anything wrong with the code. Anyone have any ideas?File is an invalid type (.gif, .jpeg, .png or .bmp).





