Jump to content

how to display image in php


VineetDubey

Recommended Posts

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;

:)

 

Link to comment
https://forums.phpfreaks.com/topic/240793-how-to-display-image-in-php/
Share on other sites

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]

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.