PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

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 Codewalkers Forums Sponsor:
  #1  
Old August 25th, 2009, 09:25 AM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
SQL image/blob display problems

I'm new to php (and this forum) and have spent the past week trying to figure out how to display an SQL image field. I've finally gotten an image to render but it's only partially displaying the image (the rest of the image is grey - like it ran out of ink).

I'm accessing a third party database and they've not included an image's size in the database. The images that've been stored are all different sizes ranging from about 250px to about 700 px.

The smaller images render correctly about halfway then turn to grey. The larger images are correct for only about 10 px/lines and then turn to grey.

So my questions/issues are as follows: How do I get the entire image to render correctly? and How can I standardize the size of the image rendered - to a width of say, 250px?

Here's the code that I'm using:
PHP Code:
 display.php
<?php
$id 
$_GET['id'];
$linkweb mssql_connect($ip$un$pw)or die(mssql_get_last_message());
mssql_select_db ($db$linkweb);
 
$sql "SELECT Photo, ClientID
           FROM tblClient_Photo
           WHERE ClientID=$id"
;
$result mssql_query($sql,$linkweb) or die('Query failed: '.$sql);
if(
mssql_num_rows($result)){
    while(
$row mssql_fetch_array($result)){
      
header("Content-type: image/jpeg;");
      
$photo=($row['Photo']);
      print 
$photo;
    }
}
?> 


The display line is as follows: <img src='display.php?id=".$id."'>

Let me know if there's any other information you need to consider this problem.

I appreciate any insight or help provided.

Last edited by jlisham : August 25th, 2009 at 09:37 AM.

Reply With Quote
  #2  
Old August 25th, 2009, 01:47 PM
LLX LLX is online now
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,291 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 18 h 34 m 21 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
i found this makes things really easy, it's a function i created some time ago.

PHP Code:
function DynamicPicReturn($imgnameA$maxwidth 'N/A'$absoluteBASE "/home/joe/public_html/site/"$BASE "http://www.site.com/"){
$imgpthA $absoluteBASE.$imgnameA;
$displayimgpthA $BASE.$imgnameA;

if (
trim($imgnameA)==''){$display '<img src="'.$BASE.'images/spacer.gif">';}else{
list(
$width$height$type$attr) = @getimagesize($imgpthA);
if (
$maxwidth != 'N/A'){
    
$newwidthdiv $width $maxwidth;
    @
$height $height $newwidthdiv;
    
$width $maxwidth;}
    if (
$type 4){ 
$display '<img src="'.$displayimgpthA.'" border="0" width='.$width.' height='.$height.'>';
} else {
$display '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width='.$width.' height='.$height.'>';
$display .= '<param name="movie" value="'.$displayimgpthA.'">';
$display .= '<param name="quality" value="high">';
$display .= '<param name="wmode" value="transparent">';
$display .= '<embed src="'.$displayimgpthA.'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='.$width.' height='.$height.'></embed></object>';
}
// end of if else for images/swf switch
};
return 
$display;
};
//function 


then just call it like so

echo DynamicPicReturn("path for image", $width).'<BR>';


What this does is call the picture (try putting it in a loop to check your database) and you can specify the second parameter Width to force them all to resize to the same width (but different heights)
__________________
29 years of creative writing
13 years of HTML
10 years of Photoshop
6 years of PHP/MySQL
And I never knew Photoshop could do HTML until 2004!
You learn something new every day.

Reply With Quote
  #3  
Old August 27th, 2009, 10:17 AM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
I appreciate your response. Thank you!

To my novice eye it looks like this code's not pulling images from a database but a location/folder and resizing them. The resizing part is great and I think I can see how to make it work once the images have been converted from binary to jpg, but that's really the first problem I have - the conversion to jpg.

Thoughts, anyone?

Reply With Quote
  #4  
Old August 27th, 2009, 11:29 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,069 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 6 Days 7 h 58 m 46 sec
Reputation Power: 5
you shouldn't have to do any sort of conversion from the binary data to the image. check out the user comments on the manual page for mssql_query(). there are a lot of posts and some sample code that should help you.

Reply With Quote
  #5  
Old August 27th, 2009, 11:42 AM
LLX LLX is online now
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,291 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 18 h 34 m 21 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by jlisham
I appreciate your response. Thank you!

To my novice eye it looks like this code's not pulling images from a database but a location/folder and resizing them. The resizing part is great and I think I can see how to make it work once the images have been converted from binary to jpg, but that's really the first problem I have - the conversion to jpg.

Thoughts, anyone?


well yes the files are stored in a folder but their path is in a database. Normally i save the filename to the database and then apend in the function call the path. But you could just apend the file path from your database.

Id advise agaisnt storying images in the database itself as that adds unnessicary over head, referencing a folder is cleaner, IMHO

Reply With Quote
  #6  
Old August 27th, 2009, 01:40 PM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
Thank you for your response/time.

Sorry, I misspoke the question somewhat. I meant conversion only in the sense that a binary data field would be displayed as a jpg.

I'm using the same code as the msssql_query() page you referenced and it does render the image - just not all of it. I'm missing something... and that something seems to be limiting the amount of 'image' that can be seen. Is this an ini issue? or some other config issue? Timeout?

I'm usually able to find something to point me in the right direction but haven't located a heck-of-a lot of information on this (I've been looking!). That must mean this is either really easy or a really bad idea. Either way I'm stuck with only half an image.

This appears to be the important bit of code needed:
PHP Code:
 header("Content-type: image/jpeg;"); 
      
$photo=($row['Photo']); 

and I'm using that.

Reply With Quote
  #7  
Old August 27th, 2009, 01:43 PM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by LLX
well yes the files are stored in a folder but their path is in a database. Normally i save the filename to the database and then apend in the function call the path. But you could just apend the file path from your database.

Id advise agaisnt storying images in the database itself as that adds unnessicary over head, referencing a folder is cleaner, IMHO


Unfortunately the storage method wasn't my choice - I'm pulling data from a third party database...

Reply With Quote
  #8  
Old August 27th, 2009, 02:04 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,069 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 6 Days 7 h 58 m 46 sec
Reputation Power: 5
I honestly don't know. It sounds like the data in the table is being truncated like from either the blob field set to small of a size or possibly the connection is timing out and stopping after retrieving the result half way or maybe an error like a notice error/warning is causing a problem and the error is being spit out half way through the image so it stops at that point. I would check the error thing, just remove the header() call and you will get the image as if you opened it in notepad. then look through all that randomness to see if there is an error in the middle somewhere. if that doesn't work, maybe check the size of the image you get back from the result and compare that to the same image on the server. a simple count of characters in the source of the image should match or at least if you notice a big difference it could help narrow it down.

Reply With Quote
  #9  
Old August 31st, 2009, 07:12 PM
LLX LLX is online now
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,291 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 18 h 34 m 21 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
adding to lamma's comments, can you do a url direct access to the image. ie can you point your browser manually at www.site.com/images/myimg.jpg

if so then we know the image is good and just retrieving it from the database is the problem

Reply With Quote
  #10  
Old September 1st, 2009, 10:53 AM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
(BTW - I'm just way out of my depth!)

I've removed the header info and the images render as before. I did take a look at the image properties and they all seem to be either 4028k or 8194k (this latter is of an image that is almost all grey) and this seems like it should be an important clue. I looked at the ini file and can't find a corresponding limit - like max size is 4M or somesuch.

I'm trying to connect with the software developer who owns the database and am hoping that it'll be all downhill from there.

Is it usual to store blob images without including file type and size? It seems like I should be specifying the file size in the rendering code somewhere but as far as I can tell, it's not being collected.

one additional piece of info - the images are available through the application and also by report generation (MS Word) and are rendering correctly in those formats.

Last edited by jlisham : September 1st, 2009 at 11:15 AM.

Reply With Quote
  #11  
Old September 1st, 2009, 11:16 AM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by LLX
adding to lamma's comments, can you do a url direct access to the image. ie can you point your browser manually at www.site.com/images/myimg.jpg

if so then we know the image is good and just retrieving it from the database is the problem


The images don't exist in that format - they're stored as type IMAGE in a SQL database. or am I missing something?

Reply With Quote
  #12  
Old September 1st, 2009, 11:22 AM
LLX LLX is online now
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,291 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 18 h 34 m 21 sec
Reputation Power: 4
Send a message via AIM to LLX Send a message via Yahoo to LLX
Quote:
Originally Posted by jlisham
The images don't exist in that format - they're stored as type IMAGE in a SQL database. or am I missing something?


what i'm saying is save the database content locally in say word, (if you can access it via say php my admin) and try and deplay it in hard code.

Don't extract and convert, do a hard copy convert just to make sure the file itself isn't bad.

Reply With Quote
  #13  
Old September 29th, 2009, 01:37 PM
jlisham jlisham is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 9 jlisham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 14 m 18 sec
Reputation Power: 0
turns out it was an ini file setting after all - just made the following adjustments
PHP Code:
Valid range 0 2147483647.  Default = 4096.
mssql
.textlimit 2147483647         

Valid range 0 2147483647.  Default = 4096.
mssql
.textsize 2147483647 


and problem solved.

Thanks for all your efforts!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > SQL image/blob display problems


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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek