Uploaded image not being stored properly in the database (php mysql) -
i trying store uploaded images in database. however, images won't display, , when take @ table phpmyadmin in image column see stuff [blob - 20b] instead of actual size should have.
the display script works fine, inserted image through phpmyadmin instead of upload script , displayed fine.
my form:
<form id="productform" action="index.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="product_id" value="' . $values['product_id'] . '" /> <input type="file" name="image" /> </form>
processing code:
$clean['image'] = mysqli_real_escape_string($dbc, file_get_contents($_files['image']['tmp_name'])); mysqli_query($dbc, " insert product_images (product_id, mime, image) values ('{$clean['last_product_id']}', '{$clean['mime']}', '{$clean['image']}') ");
i have omitted irrelevant cause other things seem working well.
thanks
my apologies not direct answer question, suggest approach not best 1 - point advise abandon if can.
storing image data in database possible, it's 1 of things can do, shouldn't. if script sees moderate use, database can become large , unwieldy. poor or missing indexes, can expect database performance decline table size bloats each added record.
added database size, there's additional complexity of maintaining code can retrieve image data , output in manner can used client. aren't going able print
data, you'll have send headers indicate image, means separate script, http requests, , additional database call.
all around, bad method use. you're far better off writing file disk, storing path string in database, is, might add, easier code perspective. infinitely easier utilize data later, well.
best of luck!
edit
try correct current code, way:
$instr = fopen($_files['image']['tmp_name'],"rb"); $image = addslashes(fread($instr,filesize($_files['image']['tmp_name']))); mysqli_query($dbc, 'insert product_images (product_id, mime, image) values ("'.$clean['last_product_id'].'", "'.$clean['mime'].'", "'.$image.'")';
Comments
Post a Comment