#connect to the database
mysql_connect("localhost", "root", "");
mysql_select_db("masscic");
//Upload Handler to check image types
function is_image($file) {
$file_types = array('jpeg', 'gif', 'bmp'); //acceptable file types
if ($img = getimagesize($file)){
//echo '
';
//print_r($_FILES); //will return an array of information for testing
//print_r($img); //will return an array of information for testing
if(in_array(str_replace('image/', '', $img['mime']), $file_types))
return $img;
}
return false;
}
//form submission handling
if(isset($_POST['submit'])) {
//file variables
$fname = $_FILES['files']['name'];
$ftype = $_FILES['files']['type'];
$fsize = $_FILES['files']['size'];
$tname = $_FILES['files']['tmp_name'];
$ferror = $_FILES['files']['error'];
$newDir = '../uploads/'; //relative to where this script file resides
for ($i = count($fname) -1; $i >=0; $i--) {
if ($ferror[$i] =='UPLOAD ERR OK' || $ferror[$i] ==0)
{
if(is_image($tname[$i]))
{
move_uploaded_file($tname[$i], ($newDir.time().$fname[$i]));
echo '
'.$fname[$i].' -- image has been accepted';}else
echo '
'.$fname[$i].' -- is not an accepted file type';}
}
}
$sqlInsert = mysql_query("INSERT INTO files (file_names) VALUES('$fname')") or die (mysql_error());