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
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.