PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 5th, 2008, 04:01 AM
Meenuphp Meenuphp is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 Meenuphp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 39 sec
Reputation Power: 0
PHP5 - Image display from mysql using php

i want to display image from mysql using php.
i uploaded file to db corectly.
header("Content-Disposition: inline; filename=$trend_file_name"); i can get pdf file correctly,but can't get jpeg files.i don't identify the problem .......help me plz

Reply With Quote
  #2  
Old May 5th, 2008, 08:34 AM
lnxgeek lnxgeek is offline
I AM A GOLDEN GOD
Dev Shed God (5000 - 5499 posts)
 
Join Date: Apr 2003
Location: cannot find symbol: method showLocation()
Posts: 5,278 lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level)lnxgeek User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 21 h 17 m 36 sec
Reputation Power: 564
What is it doing / not doing? Please be more specific.

A JPEG file of course, has the mime type "image/jpeg". Did you properly store the mime type and are using header() with the 'Content-type' header to output that? What about the file size ('Content-length')?

Are you storing the files in at least a MEDIUMBLOB type field?

Can you show us the relevant code?
Comments on this post
Hammer65 agrees: You are correct oh golden one!
__________________
BookMooch.com : Give books away. Get books you want.

Reply With Quote
  #3  
Old May 5th, 2008, 12:10 PM
Hammer65's Avatar
Hammer65 Hammer65 is offline
Web Developer/Musician
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: Lincoln Nebraska
Posts: 1,927 Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 19 h 8 m 50 sec
Reputation Power: 500
Send a message via AIM to Hammer65
Setting aside for the moment the fact that storing files in the database is inadvisable, the content type is the most important header to send in this case. In many cases cache control headers are also necessary. A good reference for this is the PHP manual page for header(), don't forget to read the comment section.
__________________
"Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony! Well, but you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! I mean, if I went 'round saying I was an emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!"

Reply With Quote
  #4  
Old May 8th, 2008, 12:16 PM
Meenuphp Meenuphp is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 Meenuphp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 39 sec
Reputation Power: 0
if((isset ($_FILES['trend_file']['name']) && is_uploaded_file($_FILES['trend_file']['tmp_name'])))
{
$fileName = $_FILES['trend_file']['name'];
$tmpName = $_FILES['trend_file']['tmp_name'];
$fileSize = $_FILES['trend_file']['size'];
$fileType = $_FILES['trend_file']['type'];
$fp = fopen($tmpName, 'r');
$content_file = fread($fp, filesize($tmpName));
$content_file = addslashes($content_file);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}


$grpfil=mysql_query("update `property_trend` set `trend_file_size`='$fileSize',`trend_file_type`='$fileType',`trend_file_name`='$fileName',`trend_fil e`='$content_file' where `trend_id`='$filepathid'") or die("111");
}

i used for uploading image
**************************************************
$select_doc=mysql_query("select `trend_file_size`,`trend_file_type`,`trend_file_name`,`trend_file` from `property_trend` where `trend_id`='$trend_id' ");
$row = mysql_fetch_array($select_doc);


$trend_file=$row['trend_file'];
$trend_file_name=$row['trend_file_name'];

$size =$row['trend_file_size'];
$type=$row['trend_file_type'];

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: inline; filename=$trend_file_name");

echo $trend_file;

******************************************' this code for dispaly ..

this the code am using. trend_file_type value is image/jpeg
and trend_file type is mediumblob ...............


Any hope?
i want to display this image on html page ,not for downloading....


Quote:
Originally Posted by lnxgeek
What is it doing / not doing? Please be more specific.

A JPEG file of course, has the mime type "image/jpeg". Did you properly store the mime type and are using header() with the 'Content-type' header to output that? What about the file size ('Content-length')?

Are you storing the files in at least a MEDIUMBLOB type field?

Can you show us the relevant code?

Reply With Quote
  #5  
Old May 8th, 2008, 12:24 PM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2001
Location: Ft Myers, FL
Posts: 4,003 kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)kicken User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115392 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 2 Weeks 4 Days 16 h 44 m 28 sec
Reputation Power: 414
Send a message via ICQ to kicken Send a message via AIM to kicken Send a message via MSN to kicken
Quote:
Originally Posted by Meenuphp
Any hope?
i want to display this image on html page ,not for downloading....


How are you linking to this file in order to display the image?

<img src="getTrendImage.php?tend_id=4" />


Is it just trying to download the image instead of display it in the browser? If you go ahead and download it, does it open properly in an image program (ie is it a valid image)?
__________________
Spidermonkey Tutorial

http://wiser.aoeex.com/ - Long term project (offline due to evil crawlers and lack of content)
http://www.aoeex.com/gmap.php - Put yourself on the map

Reply With Quote
  #6  
Old May 8th, 2008, 01:33 PM
Hammer65's Avatar
Hammer65 Hammer65 is offline
Web Developer/Musician
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: Lincoln Nebraska
Posts: 1,927 Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Hammer65 User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 19 h 8 m 50 sec
Reputation Power: 500
Send a message via AIM to Hammer65
Quote:
Originally Posted by Meenuphp
if((isset ($_FILES['trend_file']['name']) && is_uploaded_file($_FILES['trend_file']['tmp_name'])))
{
$fileName = $_FILES['trend_file']['name'];
$tmpName = $_FILES['trend_file']['tmp_name'];
$fileSize = $_FILES['trend_file']['size'];
$fileType = $_FILES['trend_file']['type'];
$fp = fopen($tmpName, 'r');
$content_file = fread($fp, filesize($tmpName));
$content_file = addslashes($content_file);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}


$grpfil=mysql_query("update `property_trend` set `trend_file_size`='$fileSize',`trend_file_type`='$fileType',`trend_file_name`='$fileName',`trend_fil e`='$content_file' where `trend_id`='$filepathid'") or die("111");
}

i used for uploading image
**************************************************
$select_doc=mysql_query("select `trend_file_size`,`trend_file_type`,`trend_file_name`,`trend_file` from `property_trend` where `trend_id`='$trend_id' ");
$row = mysql_fetch_array($select_doc);


$trend_file=$row['trend_file'];
$trend_file_name=$row['trend_file_name'];

$size =$row['trend_file_size'];
$type=$row['trend_file_type'];

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: inline; filename=$trend_file_name");

echo $trend_file;

******************************************' this code for dispaly ..

this the code am using. trend_file_type value is image/jpeg
and trend_file type is mediumblob ...............


Any hope?
i want to display this image on html page ,not for downloading....


addslashes() is very insecure, you will probably need to base64 encode that data, but since I would never store such data in a database, I'm not certain of that. You also escape the data twice if magic_quotes is not enabled, which makes no sense.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Image display from mysql using php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway