Jump to content

where images are storing mysql databse


jgkgopi

Recommended Posts

I have insert image using this following code but i want to know where it is storing

i want file path of the imahe what i have inserted

<html>

<head><title>File Insert</title></head>
<body>
<h3>Please Choose a File and click Submit</h3>

<form enctype="multipart/form-data" action=
"<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input name="userfile" type="file" />
<input type="submit" value="Submit" />
</form>
</body>

<?php
// check if a file was submitted
if(!isset($_FILES['userfile'])) {
echo '<p>Please select a file</p>';
}
else
{
try {
upload();  //this will upload your image
echo '<p>Thank you for submitting</p>';  //Message after uploading image
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
// the upload function

function upload(){
include "file_constants.php";
$maxsize = $_POST['MAX_FILE_SIZE'];
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {

// check the file is less than the maximum file size
if( $_FILES['userfile']['size'] < $maxsize)
{
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));

// put the image in the db...
// database connection
mysql_connect($host, $user, $pass) OR DIE (mysql_error());

// select the db
mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error());

// our sql query
$sql = "INSERT INTO test_image
(image, name)
VALUES
('{$imgData}', '{$_FILES['userfile']['name']}');";

// insert the image
mysql_query($sql) or die("Error in Query: " . mysql_error());

}
}
else {
// if the file is not less than the maximum allowed, print an error
echo
'<div>File exceeds the Maximum File limit</div>
<div>Maximum File limit is '.$maxsize.'</div>
<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].
' bytes</div>
<hr />';
}
}
?>
</html>

Link to comment
Share on other sites

i want file path of the imahe what i have inserted

 

There isn't one. The code you have is storing the raw data of the image into the database. There isn't even a "file" with the process you are taking. If you want to display the image you will have to read the data from the database and send it as a jpg image. Here is a page that shows the process in a very rudimentary manner: http://digitalpbk.blogspot.com/2007/04/using-php-for-more-than-html.html

 

Of course, you could go the other way. Instead of storing the raw data in the database you could save the actual file on your server and store the path to the file in your database.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.