Using HTML input type file not working

I have a form and a script that handles the submit event. In the script I have variables representing the form fields, including the field. The $screenshot variable won’t read the code $screenshot = $_FILES[‘pic’][‘name’]; I can’t echo it or display it in any other way. In other words its empty. The whole code is below.

[code]<?php
include(‘php/header.php’);
include(‘php/navigation.php’);
define(‘UPLOADPATH’, ‘images/’);

?>

Upload an image to the gallery:





<?php
if (isset($_POST['submit']))
{
	$name = $_POST['name'];
	$date = $_POST['date'];
	$desc = $_POST['desc'];
	$screenshot = $_FILES["pic"]["name"];
	
	if (!empty($name) && !empty($date) && !empty($desc) && !empty($screenshot))//$screenshot is empty
	{
		$target = UPLOADPATH . $screenshot;
		if (move_uploaded_file($_FILES['pic']['tmp_name'], $target))
		{
			
			$connection = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME)or die('error with the connection');
			$query = "INSERT INTO photos VALUES (0, '$name', '$date', '$desc', '$screenshot')";
			mysqli_query($connection, $query)or die("error with the query");
		}
		else
		{
			echo "move file failed";	
		}
	}
	else
	{
		echo "field(s) are empty";	
	}
}//end if submit

?>

<?php include('php/footer.php'); ?>[/code]

Replace

[PHP]

[/PHP]

With

[PHP]

[/PHP]

Thanks. That worked.

mark

Sponsor our Newsletter | Privacy Policy | Terms of Service