Inserting Image into MYSQL Database (1 Viewer)

RajaGautam

Registered User.
Local time
Today, 17:15
Joined
Apr 5, 2013
Messages
10
PHP:
Hi! I have a two basic extension file for Uploading and Inserting Image in MySQL. First I have a ADD.HTML File & Second INSERT.PHP, ADD.HTML provide form input box for image upload, it goes as below:

ADD.HTML

<html>

<head><title>Form upload to DataBase</title>

</head>

<body>

<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">

<input name="MAX_FILE_SIZE" value="102400" type="hidden">

<input name="image" accept="image/jpeg" type="file">

<input value="Submit" type="submit">

</form>

</body>

</html>

Second, I have INSERT.PHP to insert image to MySQL Database, which code is as below:

INSERT.PHP

<?php

// Create MySQL login values and

// set them to your login information.

$username = "root";

$password = "****** ";

$host = "localhost";

$database = "binary";

// Make the connect to MySQL or die

// and display an error.

$link = mysql_connect($host, $username, $password);

if (!$link)

 {

die('Could not connect: ' . mysql_error());

}

// Select your database

mysql_select_db ($database);

// Make sure the user actually

// selected and uploaded a file

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) 

{

// Temporary file name stored on the server

$tmpName = $_FILES['image']['tmp_name'];

// Read the file

$fp = fopen($tmpName, 'r');

$data = fread($fp, filesize($tmpName));

$data = addslashes($data);

fclose($fp);

// Create the query and insert

// into our database.

$query = "INSERT INTO tbl_images ";

$query .= "(image) VALUES ('$data')";

$results = mysql_query($query, $link);

// Print results

print "Thank you, your file has been uploaded.";

}

else 

{

print "No image selected/uploaded";

}

// Close our MySQL Link

mysql_close($link);

?>

Everything is right, i can upload image to my binary database with table tbl_images, but i can only upload image of size <= 58.7 KB & when i upload image with size 223 KB it display message as: 

No image selected/uploaded

How to increase image size in above code? Please help me! i'm in dilemma.
 

Users who are viewing this thread

Top Bottom