![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| 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: * 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 |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#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 |
|
|
|
| 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 |
|
|
#2 (permalink) |
|
Registered User
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. |
|
|
|
|
|
#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 |
|
|
|
|
|
#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. |
|
|
|
|
|
#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. <? ; 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();
}
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();
}
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();
}
~ K |
|
|
|
|
|
#7 (permalink) |
|
Registered User
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();
}
|
|
|
|
|
|
#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. <? 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>
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 |
|
|
|
|
|
#9 (permalink) |
|
Registered User
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...");
}
?>
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();
}
Hope this helps. |
|
|
|
|
|
#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> ~ K |
|
|
|
|
|
#11 (permalink) |
|
Registered User
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:
|
|
|
|
|
|
#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..."); } ?>
~ K |
|
|
|
|
|
#13 (permalink) |
|
Registered User
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); |
|
|
|
|
|
#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"); 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~}ۖ
~ k |
|
|
|
|
|
#15 (permalink) |
|
Registered User
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");
|
|
|
|
|
|
#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...");
}
?>
Code:
<html> </body> <p> <img src="getpicture.php?fid=2"></img></p> </html> </body> Please check the above listed codes to see if theres anything wrong in my code. Thanks, K |
|
|
|
|
|
#17 (permalink) |
|
Design Team Member
|
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 | |
|
|
|
![]() |
| Thread Tools | |
|
|