Forum Moderators: coopster
<html>
<body>
<h3>Please Choose a File and click Submit</h3>
<form enctype="multipart/form-data" action="" method="post">
<input name="userfile[]" type="file" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
<?php
// the upload function
function upload(){
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
// $imgData = addslashes($_FILES['userfile']);
// get the image info..
$size = getimagesize($_FILES['userfile']['tmp_name']);
// put the image in the db...
// database connection
mysql_connect($mysql_server, $mysql_user, $mysql_password) OR DIE (mysql_error());
// select the db
mysql_select_db ("database") OR DIE ("Unable to select db".mysql_error());
// our sql query
$sql = "INSERT INTO test
( image_id , image_type ,image, image_size, image_name)
VALUES
('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";
// insert the image
if(!mysql_query($sql)) {
echo 'Unable to upload file';
}
}
}
?>