0)
{
echo "Return Code: " . $_FILES["Picture"]["error"] . "
";
}
else {
//outputs name, type, size, and temp name
echo "Upload: " . $_FILES["Picture"]["name"] . "
";
echo "Type: " . $_FILES["Picture"]["type"] . "
";
echo "Size: " . ($_FILES["Picture"]["size"] / 1024) . " Kb
";
echo "Temp file: " . $_FILES["Picture"]["tmp_name"] . "
";
//checks if picture exists in the folder already, if it does, fails
if(file_exists("trees/" . $_FILES["Picture"]["name"]))
{
echo $_FILES["Picture"]["name"] . " already exists. ";
echo "Go back and try again!";
exit;
}
else {
//moves image into trees folder on the server
move_uploaded_file($_FILES["Picture"]["tmp_name"], "trees/" . $_FILES["Picture"]["name"]);
echo "Stored in: " . "trees/" . $_FILES["Picture"]["name"];
}
}
//inserts the new tree into the database using the variables
$query = "insert into tree values ('NULL', '".$specie."', '".$ID."', '".$date."', '".$designation."', '".$family."', '".$genus."', '".$picture."', 'NULL')";
$result = $db->query($query) or die ('Query Failed: ' . mysql_error());
}
//if picture isnt a jpeg or gif or is to big, outputs invalid file
else {
echo "Invalid File";
exit;
}
}
//a picture is not required so if the picture field is empty the file upload will be bypassed and jump to here where the record will be inserted without the picture
else {
$query = "insert into tree values ('NULL', '".$specie."', '".$ID."', '".$date."', '".$designation."', '".$family."', '".$genus."', '".$picture."', 'NULL')";
$result = $db->query($query) or die ('Query Failed: ' . mysql_error());
}
//checks if the process was successful
if ($result) {
echo "Process Successful!
";
echo "Go Back";
} else {
echo "An error has occurred, go back and try again!";
exit;
}
$db->close();
?>