I have written the following code to upload an image into the database, however, everytime I choose an image and press "upload" all I get is "Waiting for localhost" and nothing loads on the browser. I'm using xampp for my localhost. The database name is "votingsystem" and the table to insert the image is "photo".
After running this php file I am also unable to run other php files since they all exhibit the same problem on the browser by saying "Waiting for localhost" when trying to run them. As such I have to restart my file editor and run it again. It's been a recurring problem.
<?php
/**
* Created by PhpStorm.
* User: user1
* Date: 10-Jul-15
* Time: 9:19 PM
*/
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("votingsystem") or die(mysql_error());
if(isset($_POST['Upload']))
{
$file = $_FILES['image']['tmp_name'];
if(!isset($file))
{
echo "Please select an image.";
}
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == FALSE)
{
echo "That's not an image";
}
else
{
$insert = mysql_query("INSERT INTO photo VALUES ('', '999', '$image_name', '$image')");
if(!$insert)
{
echo "Problem uploading image!";
}
else
mysql_query($insert) or die(mysql_error());
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Image Upload</title>
</head>
<link rel="stylesheet" type="text/css" href="image.css">
<body>
<form action="image.php" method = "post" enctype="multipart/form-data">
<input type = "file" name = "image">
</br>
<input type = "submit" value = "Upload">
</form>
</body>
</html>