konx80 Posted March 25, 2009 Share Posted March 25, 2009 I'm having a problem getting images to work after uploading/downloading from mysql database. Files seem to upload and download normally. when i open one of my downloaded photos i get "no preview available". code: uploader (form submission): $img = "STOCK_".mktime().".jpg"; $text = $_POST['text']; $md5 = md5($img); $type = $_FILES['file']['type']; $size = $_FILES['file']['size']; $fp = fopen($_FILES['file']['tmp_name'], 'r'); $content = fread($fp, filesize($_FILES['file']['tmp_name'])); $content = addslashes($content); fclose($fp); $query = "INSERT INTO images SET name='$img',data='$content',md5='$md5',type='$type',size='$size'"; mysql_query($query); --------------------------------------------------------- downloader: ob_start(); include('config.php'); $iid = $_GET['iid']; $query = "SELECT name,data,md5,type,size FROM images WHERE id='$iid' LIMIT 1"; $result = mysql_query($query); list($name,$data,$md52,$type,$size) = mysql_fetch_array($result); header("Content-Length: $size"); header("Content-Type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $data; exit; ob_end_flush(); any help is appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/151005-problem-with-storing-images-in-mysql/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.