I thought this code was perfect but unfortunately, every time I attempt to upload an image, it will only upload 1 kb of data. Can anyone tell me what Im doing wrong?
<?php
$con = mysql_connect("host","login","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Database", $con);
function getimage($file){
$takeFile = fopen($file, "r");
$file = fread($takeFile, filesize($file));
fclose($takeFile);
return $file;
}
function getfileType( $name ){
$name = explode(".", $name);
$name = array_reverse($name);
$name = strtolower($name[0]);
return $name;
}
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$allowedImageTypes = array("jpg");
if(empty($_FILES['image']['tmp_name'])){
die("File not uploaded");
} else {
$fileType = $_FILES['image']['name'];
if(in_array(getfileType($fileType), $allowedImageTypes)){
$fileContent = getimage($_FILES['imgfile']['tmp_name']);
$sql="INSERT INTO post (poster, poster2, title, category, tagline, thearticle, image)
VALUES
('$_POST[poster]','$_POST[poster2]','$_POST[title]','$_POST[category]','$_POST[tagline]','$_POST[thearticle]','$content ')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
if(mysql_affected_rows() > 0){
die("Image inserted successfully");
} else {
die("Image can not be inserted check your submission");
}
mysql_close($con);
} else {
die("This is not a valid image type");
}
}
?>