upload image to folder and saving image name in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

upload image to folder and saving image name in database

Post 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>
 
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

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

Post 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.
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

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

Post by phphunger »

Thank you mate...Its working..
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

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

Post by markusn00b »

phphunger wrote:Thank you mate...Its working..
No problem.

Take care,
Mark.
Post Reply