Page 1 of 1

upload image to folder and saving image name in database

Posted: Wed Oct 21, 2009 2:18 am
by phphunger
Hi,

As i am working out on uploading image in the upload folder of my system's directory and parallely saving the uploaded image name in the mysql database server. The code is working but the image name is not saving the database. Instead of saving the image name it saves the name as BLOB-8B, BLOB-10B etc..Can anyone tell me wats my mistake.

And also creating database the which datatype should i use for saving the image in database. Please suggest...

My code:
uploadimage.php

Code: Select all

<?php
if ($_POST["action"] == "Load")
{
$folder = "upload/";
move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
echo "<p align=center>File ".$_FILES["filep"]["name"]."loaded...";
$result = mysql_connect("localhost", "root", "") or die ("Could not save image name Error: " . mysql_error());
mysql_select_db("tests") or die("Could not select database");
mysql_query("INSERT into dbProfiles (photo) VALUES('".$_FILES['filep']['name']."')");
if($result) 
    { 
    echo "Image name saved into database"; 
    }
}
?>
index.php

Code: Select all

<html>
<head>
</head>
<body>
 
<form action="uploadimage.php" method="post" enctype="multipart/form-data">
<table border="0" cellspacing="0" align="center" cellpadding="3" bordercolor="#cccccc">
<tr>
<td>File:</td>
<td><input type="file" name="filep" size=45></td>
</tr>
<tr>
<td colspan=2><p align="center">
<input type="submit" name="action" value="Load">
</td>
</tr>
</table>
</form>
 
      <?php
          ?>
</body>
</html>
 

Re: upload image to folder and saving image name in database

Posted: Wed Oct 21, 2009 11:08 am
by markusn00b
If you are only saving the name of the file to the database, then the column data type needs to be something like a varchar(20). You are not saving blob data (binary) to it, so there's no need to use the blob data type.

Re: upload image to folder and saving image name in database

Posted: Thu Oct 22, 2009 1:20 am
by phphunger
Thank you mate...Its working..

Re: upload image to folder and saving image name in database

Posted: Thu Oct 22, 2009 6:48 am
by markusn00b
phphunger wrote:Thank you mate...Its working..
No problem.

Take care,
Mark.