Jump to content

[SOLVED] Strange BLOB problem??


Craigus

Recommended Posts

Hello again Guru's.

 

I've got a simple form to add info, text and an image to MySQL.

 

It's all working correctly except the image upload. It seems to work but no matter what the filesize of the image the database shows the filesize [bLOB - 14 B] I'm not sure where I've gone wrong.

 

Any help would be greatly appreciated.

 

My insert.php;

<?php

//Connect to database
mysql_connect("localhost","****_db","****") or die(mysql_error()) ;
mysql_select_db("****_db") or die(mysql_error()) ;

//Set variables
$species = $_POST['species'];
$location = $_POST['location'];
$state = $_POST['state'];
$date = $_POST['date'];
$comments = $_POST['comments'];

//No image selected, skip;
if($_POST[image] == "none") { 

//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);

//continue from here if no image selected
}
else {

//Insert into database
$sql="INSERT INTO ****_db (image, species, location, state, date, latlong, comments)
VALUES ('$image', '$species', '$location', '$state', '$date', '$latlong', '$comments')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }

//Results
echo "Thank you, your record has been added to the database";

}

?>

 

Cheers

Craig.

Link to comment
https://forums.phpfreaks.com/topic/158223-solved-strange-blob-problem/
Share on other sites

So the variable you are placing the image into is called $data. Where is that being used in your query?

 

Thank you..

 

And your logic is wrong anyway. The if() {} is reading the data, the else {} is where the mysql query is at.

 

Please explain?

 

I should also apologise for begin very new to this. ???

I've got this working by replacing

 

This;

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

$fp      = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);

 

With this;

$image =addslashes (file_get_contents($_FILES['image']['tmp_name']));

 

I guess I need to read more about use of if

 

Thanks for the input.

 

Craig.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.