i have made this form where a person enters trainer details and an image,when i submit the image isn't uploaded but it returns that "invalid file"
PHP Code:
<?php
$type = $_FILES['userfile']['type'];
if ( ($type == 'image/png' ) || ($type == 'image/gif' ) || ($type == 'image/pjpeg' ) ) {
move_uploaded_file($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']);
echo "Upload Complete!";
}
else {
die ("Invalid file type");
}
/* file: regprocess.php */
/* wrriten: 3-31-05 */
if(isset($_POST['register']))
{
//oodles of variables from teh form
$name = $_POST['name'];
$make = $_POST['make'];
$colour = $_POST['colour'];
$discription_1 = $_POST['discription_1'];
$discription_2 = $_POST['discription_2'];
$price = $_POST['price'];
$stock = $_POST['stock'];
$image_dir = $image_dir = $_FILES['userfile']['name'];
//make sure them gooses filled in everything
$errors = 0;
$emessage = "<center><font face=\"Verdana\">Sorry, we enounctered the following errors when processing your registration:<br /><ul>";
if(empty($name) || empty($make)|| empty($colour)|| empty($discription_1)|| empty($discription_2)|| empty($price)|| empty($stock) || empty($image_dir))
{
$errors = 1;
$emessage .= "<li>Sorry, you must fill in <strong>all</strong> fields. Please go back and try again.</li>";
}
//if the gooses made errors, show em'
if($errors != 0)
{
$emessage .= "</font></center>";
die("$emessage");
}
//connect to el database
//edit settings to yours, you goose you!
mysql_connect("localhost", "root", "") or die(mysql_error());
//change this to your DB's name
mysql_select_db("school") or die(mysql_error());
//perform query, inseting user submitted data
mysql_query("INSERT INTO school (make,name,image,colour,trainer_info_1,trainer_info_2,stock,price ) VALUES ('$make','$name','$image_dir','$colour','$image_dir','$discription_1','$discription_2','$stock','$price')") or die(mysql_error());
//give them a nice pat on the back for doing everything just right
echo("<center><font face=\"Verdana\">Thanks for registering. We will get back to you as soon as possible.</font></center>");
}
?>