Jump to content

Send images to Database(MYSQL) then show them


bemax

Recommended Posts

Hi

I'm working with php in my project at school. Now I have a problem, it's a system where I want the administrator to chose a logo from his computer and submit it. Then show it when registed persons login. I'm using Mysql - and I want load images in my database. Can someone help me with this code?  Or if there is an other way I can get it help please!

 

Thanks

Hello bemax!

I'm not an expert, really not but maybe this can help... Iwas trying to do the same thing not to long ago and it's true it's easyer to save the directory path as varchar but if you really need to you can make a BLOB instead of a VARCHAR and there you can save raw pictures or pdf files to later recuperate from your website. here is a little script that worked for me be4 but really slows down database.

 

I can't really explain it to you but a fast google search for mysql blob should get you going.


$file = fopen ($_FILES["userfile"]["tmp_name"], "rb" );
//get temp size
$size = filesize ($_FILES["userfile"]["tmp_name"]);
//read temp file
$content = fread ($file, $size);
//protects by / /
$userfile = addslashes ($content);

$sql = "INSER INTO image (image) VALUES ("'{$userfile}'" )";
@mysql_query ($sql, $connection);

// gets picpour recuperer l'image
$sql = "SELEC * FROM image WHERE image_id=".$id_image;
$result = mysql_query ($sql, $connection);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
//gets bontent in binary mode
$image = $row["image"];
//shows pic
echo $image; 

 

there are a lot of codes out there that can help you out! hope you get a good grade ;)

 

 

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.