Articillusion
Articillusion

Reputation: 45

On inserting BLOB data from php to MySQL, I can't see the accurate data type

Basically working on a test to get an idea about how to upload/display images in relation betweehn php/mysql.

The problem is after I upload the image, on database, BLOB column just dipslays the "im" instead of "image/jpeg". What could be the problem that is inserting the data as an "im"?

Many Thanks

Here is the Code

$aname = $_POST['aname'];
$adetails = $_POST['adetails'];
$aphoto = addslashes(file_get_contents($_FILES['aphoto']['tmp_name']));
$image = getimagesize($_FILES['aphoto']['tmp_name']); //to know about image type etc.
$aphototype = $image['mime'];


$q = "INSERT INTO animaldata VALUES('','$aname','$adetails','$aphoto','$aphototype')";

Upvotes: 1

Views: 790

Answers (1)

user1499731
user1499731

Reputation:

My best guess is the column you're inserting last should be a varchar, or is not long enough (e.g. only 2 characters allowed max), or something similar. Check your table structure too!

Note by inserting into animaldata without specifying which columns, you're also creating a little bit of ambiguity. I'd recommend naming the columns, and possibly having a default value for your first column...

INSERT INTO animaldata
    (Name, Details, Photo, PhotoType)
    Values('$aname', '$adetails', '$aphoto', '$aphototype');

Look into prepared statements too... make your statements a little more secure ;)

Upvotes: 1

Related Questions