File upload restrictions
I am using the following script to upload photos to server and store details in a database
I'm a bit stuck as how to add restrictions such as size and type to this script?
Any help would be appreciated.
Tom
<?php
//this is the directory where the images images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
// this gets all the other info from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("host", "user", "pass") or die(mysql_error()) ;
mysql_select_db("DB") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO employees (name,email,phone,photo)
VALUES ('$name', '$email', '$phone', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
$note['success'] = 'The file '. basename( $_FILES['photo']['name']). ' has been uploaded, and your information has been added to the directory';
}
else {
//Give an error if it's not
$note['error'] = 'Sorry, there was a problem uploading your file.';
}
?>
<!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=UTF-8" />
<title>Untitled Document</title>
</head>
<body><?php
if (isset($note)) {
echo '<ul>';
foreach ($note as $alert) {
echo "<li class='warning'>$alert</li>/n";
}
echo '<ul>';
}
?>
</body>
</html>
