Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 07-20-2009, 06:26 AM   #1 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Image (saved in database) not displaying

Hello:

I read the tutorial for "Uploading files to the database." I could upload the image file to the database but couldn't display it. I think I'm doing something wrong from the getpicture.php section. Here's my getpicture.php code:
<?
if(isset($_GET['fid']))
{
// connect to the database
include "connect.php";

// query the server for the picture
$fid = $_GET['fid'];
$query = "SELECT * FROM images WHERE fid = '$fid'";
$result = mysql_query($query) or die(mysql_error());

// define results into variables
$name=mysql_result($result,0,"name");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");
$content=mysql_result($result,0,"content");

// give our picture the proper headers...otherwise our page will be confused
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;

mysql_close();
}else{
die("No file ID given...");
}

?>

And I entered the following code to display the image:
<img src="getpicture.php?fid=1">
But it doesn't display any image, instead it shows a box with a cross. Please help...


~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 07-20-2009, 07:23 PM   #2 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

Visit getpicture.php?fid=1 in your browser as if it were a page and tell us what errors come up.

Also, if you could use [code] or [php] tags when you post code, that would be good.

Last edited by FredT; 07-20-2009 at 07:30 PM.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-21-2009, 05:13 AM   #3 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

I opened the getpicture.php in my browser, it did not give me any error, in fact it displays a blank page.

I forgot to mention yesterday, I had to delete some code as I got following error after selecting the image file and clicking on upload button:

Parse error: syntax error, unexpected ';' in C:\wamp\www\imageupload.php on line 125

Which was on this line, so I deleted the following entire code:
Code:
// if width is over 600 px or height is over 500 px, kill it     
if($width>600 || $height>500) 
{ 
echo $name . "'s dimensions exceed the 600x500 pixel limit."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
} 

// if the mime type is anything other than what we specify below, kill it     
if(!( 
$type=='image/jpeg' || 
$type=='image/png' || 
$type=='image/gif' 
)) { 
echo $type .  " is not an acceptable format."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
} 

// if the file size is larger than 350 KB, kill it 
if($size>'350000') { 
echo $name . " is over 350KB. Please make it smaller."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
}

After this it didn't give me any error and file got uploaded in the database.

Is it because of this?



~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-21-2009, 05:40 AM   #4 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

Sry, I just tried opening getpicture.php and did not mention the image id. When i opened it by mentioning the image id it shows small box with no image in it.

~ K

Last edited by Kan20; 07-21-2009 at 05:42 AM.
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-21-2009, 08:34 AM   #5 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

Wait, which line was 125 and what did you take out? I'm a little confused.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-22-2009, 04:04 AM   #6 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

The line which gives error is:

Code:
echo ?> <a href="form.html">Click here</a> to try again. <? ;
and the code which contained this line is:
Code:
// if width is over 600 px or height is over 500 px, kill it     
if($width>600 || $height>500) 
{ 
echo $name . "'s dimensions exceed the 600x500 pixel limit."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
}
So I deleted the full set of code, but again it gave same error (for that particular line) for this particular code:
Code:
// if the mime type is anything other than what we specify below, kill it     
if(!( 
$type=='image/jpeg' || 
$type=='image/png' || 
$type=='image/gif' 
)) { 
echo $type .  " is not an acceptable format."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
}
Same for this code also:
Code:
// if the file size is larger than 350 KB, kill it 
if($size>'350000') { 
echo $name . " is over 350KB. Please make it smaller."; 
echo ?> <a href="form.html">Click here</a> to try again. <? ; 
die(); 
}
So I deleted the all these 3 sections. Then it worked fine.


~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-22-2009, 07:23 PM   #7 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

I don't know if you got:
echo ?> <a href="form.html">Click here</a> to try again. <? ;
out of the tutorial, but I'm fairly certain that isn't right.

It's simple, though, all you have to do is take out the echo and the ;
Code:
// if width is over 600 px or height is over 500 px, kill it     
if($width>600 || $height>500) 
{ 
echo $name . "'s dimensions exceed the 600x500 pixel limit."; 
?> <a href="form.html">Click here</a> to try again. <? 
die(); 
}
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-23-2009, 06:03 AM   #8 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

I removed "echo" and ";" from all the three blocks of code, but then it gave another error pointing to the last line at the closing php tag (?>). The error is:

Parse error: syntax error, unexpected $end in C:\wamp\www\upload_testing\upload.php on line 56

Then I deleted the entire line (from all 3 blocks of code) which says:
Code:
?> <a href="form.html">Click here</a> to try again. <?
Then it worked fine. So I tried displaying the image by pasting the (<img src="getpicture.php?fid=1">) code in the getpicture.php file itself. But it didn't display the image, instead it showed a small box.

Here's the code of getpicture.php file:
Code:
<html>
<body>
<? 
if(isset($_GET['fid'])) 
{ 
// connect to the database 
include "connect.php"; 

// query the server for the picture 
$fid = $_GET['fid']; 
$query = "SELECT * FROM files WHERE fid = '$fid'"; 
$result  = mysql_query($query) or die(mysql_error()); 

// define results into variables 
$name=mysql_result($result,0,"name"); 
$size=mysql_result($result,0,"size"); 
$type=mysql_result($result,0,"type"); 
$content=mysql_result($result,0,"content"); 

// give our picture the proper headers...otherwise our page will be confused 
header("Content-Disposition: attachment; filename=$name"); 
header("Content-length: $size"); 
header("Content-type: $type"); 
echo $content; 

mysql_close(); 
}else{ 
die("No file ID given..."); 
} 

?> 

<img src="getpicture.php?fid=1">
</body>
</html>
Please help me. Okay one question:

Does that three blocks of code (if width is over 600 px or height is over 500 px kill it, if the mime type is anything other than what we specify below kill it and if the file size is larger than 350 KB, kill it) are actually required to display the image? What if we just ignore them right now and see why the image is not displaying.

Because of this my other work is also held up. Thanks for replying to my posts.

~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-23-2009, 01:55 PM   #9 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

First off, if your content-disposition is an attachment, then don't include any html in the file. That's wrong.

Code:
<? 
if(isset($_GET['fid'])) 
{ 
// connect to the database 
include "connect.php"; 

// query the server for the picture 
$fid = $_GET['fid']; 
$query = "SELECT * FROM files WHERE fid = '$fid'"; 
$result  = mysql_query($query) or die(mysql_error()); 

// define results into variables 
$name=mysql_result($result,0,"name"); 
$size=mysql_result($result,0,"size"); 
$type=mysql_result($result,0,"type"); 
$content=mysql_result($result,0,"content"); 

// give our picture the proper headers...otherwise our page will be confused 
header("Content-Disposition: attachment; filename=$name"); 
header("Content-length: $size"); 
header("Content-type: $type"); 
echo $content; 

mysql_close(); 
}else{ 
die("No file ID given..."); 
} 

?>
is fine alone for getpicture.php.

This time where I told you to remove the echo and the ; put them back in, but don't close the php block and use single quotes to echo the html... like this:
Code:
// if width is over 600 px or height is over 500 px, kill it     
if($width>600 || $height>500) 
{ 
echo $name . "'s dimensions exceed the 600x500 pixel limit."; 
echo '<a href="form.html">Click here</a> to try again.'; 
die(); 
}
Do that in all three instances you said you were having a problem with.

Hope this helps.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-24-2009, 04:17 AM   #10 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

Gr8! Just putting echo and single quotes worked. But image is still not displaying.

I deleted the HTML tags from getpicture.php file. Created new HTML file (just included the necessary code for trial), with below code:
Code:
<html>

<body>
<img src="getpicture.php?fid=2" />
</body>
</html>
Even after this the image is not displaying. What should I do to display the image?


~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-24-2009, 09:22 AM   #11 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

I'm trying to scout out what's working and what's not.

Save this as test.php and visit it as test.php?fid=2. Tell me what it says.

PHP Code:
<? 
if(isset($_GET['fid'])) 

// connect to the database 
include "connect.php"

$fid $_GET['fid']; 
$query "SELECT * FROM files WHERE fid = '$fid'"
$result  mysql_query($query) or die(mysql_error());
$numrows mysql_num_rows($result);
echo 
'Results: '.$numrows;

if(
$numrows>0){
    
// define results into variables 
    
$name=mysql_result($result,0,"name"); 
    
$size=mysql_result($result,0,"size"); 
    
$type=mysql_result($result,0,"type"); 
    echo 
"<br>$name $size $type";
} else {
    echo 
"<br>No results returned";
}
mysql_close(); 
}else{ 
die(
"No file ID given..."); 


?>
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-26-2009, 10:22 PM   #12 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

Hello Fred,

I saved the above code as test.php, and opened it as test.php?fid=2 in the browser, but it gives following error:

Code:
0){ // define results into variables $name=mysql_result($result,0,"name"); $size=mysql_result($result,0,"size"); $type=mysql_result($result,0,"type"); echo "$name $size $type"; } else { echo "
No results returned"; } mysql_close(); }else{ die("No file ID given..."); } ?>
What should I do now?

~ K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-27-2009, 04:48 PM   #13 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

That's what it says??? That's not an error... that's part of the file left unparsed.

I've never seen that before...

Add this to the top right below <?

Code:
error_reporting(E_ALL);
and try again.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-28-2009, 05:38 AM   #14 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

Fred,

Dat didn't solve d problem. But it got solved after I put "php" before "<?".

Then it displayed the image name, like this:

Results: 1
Wed_design1.png 156278 image/png


But it didn't display the image. Then I added the following line of code:
Code:
$content=mysql_result($result,0,"content");
It showed something like this:
Code:
 ��� IHDR��5��5��� }S���sRGB���� pHYs��������tIME3*V�� 
�IDATxɮ$Ygfg1"_VuM{#@@A$P %DU7>ٴ%@+z!pM?sOƸu8Ӵh*314˵u(5-YkSUBJ)c]{%Nc}-L$S*<J ZʧߌȦDd
\1JeY3==XIJL˲\.!3unnu*m\J)yVIS _ |vF.I6pJ~?RN0c`*{/@il)e[}۹OZkm33TRRaE i@D_>|̥Xc kZb
|9Oj2}Nyg�;t]BDuk)5mv)R 18|hCBzAd8ono߾=ɹ7[RnǷ󳖺>8Ms۶R TBP
^)\yZB"B�0�ZD`Kӗ$,"Iu:f޶]+6m:B~}ۖ
The entire page was filled with this. What's this?

~ k
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-28-2009, 08:44 AM   #15 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

Perfect. That page was just a test to debug the code and find the problem, not to display the image.

Add the php to your original file you were working on and that should solve the problem.

Just so you can understand what's going on, it is the
Code:
// give our picture the proper headers...otherwise our page will be confused
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
headers that tell the browser it is an image so it doesn't get confused and spit out all that gibberish.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-29-2009, 05:54 AM   #16 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

Not quite, its still not displaying the image. I dont know whats happening.
Actually, I added php and the header code in my getpicture.php file. Heres the code of getpicture.php:

Code:
<?php
if(isset($_GET['fid'])) 
{ 
// connect to the database 
include "connect.php"; 

// query the server for the picture 
$fid = $_GET['fid']; 
$query = "SELECT * FROM files WHERE fid = '$fid'"; 
$result  = mysql_query($query) or die(mysql_error()); 

// define results into variables 
$name=mysql_result($result,0,"name"); 
$size=mysql_result($result,0,"size"); 
$type=mysql_result($result,0,"type"); 
$content=mysql_result($result,0,"content"); 

// give our picture the proper headers...otherwise our page will be confused
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;

mysql_close(); 
}else{ 
die("No file ID given..."); 
} 

?>
When I opened the image_test.html file it displayed a small box on the top-right corner. Heres the code of image_test.html:

Code:
<html>
</body>
<p>
<img src="getpicture.php?fid=2"></img></p>
</html>
</body>
But if I open the getpicture.php?fid=1 directly from the browser, a save as dialog box pops up, and asks me to save the respective image. But it doesnt display the image.
Please check the above listed codes to see if theres anything wrong in my code.


Thanks,
K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-29-2009, 12:33 PM   #17 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 713
OS: Linux Mint 7

My System

Re: Image (saved in database) not displaying

That is a pretty old tutorial that is less than PHP5 compatible (PHP4 allowed for a lot of bad practices and garbage techniques). I've wanted to update that tutorial but unfortunately I don't have sufficient access to edit it. Typically people IM me and I help them that way.

I just followed the tutorial exactly and minus that ugly HTML echo fix, everything else worked fine. The image embeds into the page (no "Save As..." dialogue) in Firefox, IE, Opera, and Google Chrome. I'm wondering there is some kind of PHP/server setting that isn't displaying the headers as it should. It's hard to say, given that it works fine for me.

That said, the code is ugly and I'm itching to update it. :P
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-29-2009, 03:01 PM   #18 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

What browser are you using, Kan20?
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-30-2009, 01:51 AM   #19 (permalink)
Registered User
 
Join Date: Jul 2009
Posts: 24
OS: WIN XP service pack 2


Re: Image (saved in database) not displaying

I'm using Firefox 3.5.1.

Thanks,
K
Kan20 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 07-30-2009, 09:30 AM   #20 (permalink)
Registered User
 
FredT's Avatar
 
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2


Re: Image (saved in database) not displaying

Well, if you do agree to save it, does the picture come out correct?
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 04:36 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85