VineetDubey Posted June 30, 2011 Share Posted June 30, 2011 Hello All, I tried and search in google so many times but i not getting what i exactly want. As i was trying a bit typical task as i think though i am not able to display image using fopen and fread function, Please help me to get a code else tell me whether we can display image using these function or not. please check the below code is correct? $location='C:/xampp/htdocs/dog.jpg'; $size = getimagesize($location); $img_type = $size['mime']; $data = file_get_contents($location); //$img_data = addslashes($data); header("Content-type: ".$img_type); print $data; Quote Link to comment https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/ Share on other sites More sharing options...
Alex Posted June 30, 2011 Share Posted June 30, 2011 Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/#findComment-1236771 Share on other sites More sharing options...
VineetDubey Posted June 30, 2011 Author Share Posted June 30, 2011 yes Quote Link to comment https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/#findComment-1236871 Share on other sites More sharing options...
VineetDubey Posted June 30, 2011 Author Share Posted June 30, 2011 i tried the above code in xampp and that was not working but rt now i tried in wamp and it is working .Please let me know what was the problem. i am new in this technology. Quote Link to comment https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/#findComment-1236892 Share on other sites More sharing options...
VineetDubey Posted June 30, 2011 Author Share Posted June 30, 2011 slq: query is attached; Please let me know why this code is not displaying image. <?php $cid=mysql_connect('localhost','root',''); mysql_select_db('filesystem',$cid); $fp=fopen('DSC00194 copy.jpg','r'); $fs=filesize('DSC00194 copy.jpg'); //$data=fread($fp,$fs); //$data=addslashes($data); //mysql_query("insert into file2db(name,size,type,data) values('DSC00194 copy.jpg',$fs,'image/jpeg','$data')"); $rs=mysql_query("select * from file2db"); $row=mysql_fetch_array($rs); $data=file_get_contents($row['data']); $data=stripslashes($data); header("Content-type:".$row['type']); print $data; ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/#findComment-1236910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.