logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



PHP help

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
peacemaker



Joined: 23 May 2008
Posts: 80

PostPosted: Mon 26 Jan '09 2:28    Post subject: PHP help Reply with quote

Hi all
the problem i am facing is different, i am trying to display images form database,i m giving code that i wrote
Code:

$sql = "select * from upload ";
    
                 $result = mysqli_query($link,$sql) or die ("Could not access DB: " . mysqli_error());
                    
            echo "<table border=1>";
                    while ($row = mysqli_fetch_array($result))
                    {
                       
                  
                      
           //header("content-type: image/jpeg");
          echo $row['name'] . "<br /> <br /><br />";
          echo $row['content'];
         //echo "<img src=\"images/". $row['content'] . "\" alt=\"\"  /> <br /></td></tr>";
                         //echo "</p>";
                         //echo "</div>";
                  
                    }
           
         echo"</table>";


when i use the above code then the result come with whole bineary charactred,but the number of images shown are correct all 5 images are shown.

but if i remove the comment header statement then nothing happens
but just message is dispaly as below

"http://localhost/.../gallery.php"

I am confused wats happening
plz help me wat can be the problem. as the header statement is very important but if i uncommnet it above message come and if i comment it then every thing comes ok but it shows whole binary data insted of image.
so plz correct my code if u can
or any one has simple code as i am using BLOB datatype and images are getting uploaded properly in database.
thanks
in advance
the help will be really appriciated as i am unable to find solution since long time


[/code]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Mon 26 Jan '09 11:02    Post subject: Reply with quote

if you use a header you can't put out any code before that! The table is not correct before that. Also you can't give out text/html and binary data in the file.

correct would be something like this:
Code:

<html>
....
<img src="your.php?picture_name=picure1" />
...


your.php
Code:

<?php
$name=mysql_real_escap_string($_GET['picture_name']);
$sql = "select * from upload WHERE `name`='$name';";
   
                 $result = mysqli_query($link,$sql) or die ("Could not access DB: " . mysqli_error());
header("content-type: image/jpeg");
echo $row['content'];
?>


(Code not tested)
Back to top
peacemaker



Joined: 23 May 2008
Posts: 80

PostPosted: Tue 27 Jan '09 1:24    Post subject: Still the same problem Reply with quote

hi James
thanks for the replay and correction of code, i made 2 file 1 gallery.html where i put the 1st code , but i didnt understood the significance of variable
picture_name=picture1 does u means to say i should give the database field or something or it just a variable to pass.
I made the php file withe gallery.php
and put the remaining code in it but i modified as i need array, so i put while loop and put arrry. I didnt understood from where it wil accept or get picture name, in my web site when user click on the Gallery tab it should display the pic, thats wat i want ,i cannt pass the picture_name variable any name of the pic.
so can u explain to me plz. i am nt getting it or i am making something wrong init again
i m giving the code i modified for myself, i request you to plz modify it i am really in need of this code to get sorted.
Thanks in advance
Code:


if(!$link)
   {
      die('Could not connect: ' . mysqli_error());
   }
   else
   {
         
      
            $name=mysqli_escape_string($_GET['picture_name']);
            //
            $sql = "select * from upload WHERE `name`='$name'";
   
                $result = mysqli_query($link,$sql) or die ("Could not access DB: " . mysqli_error());
            
               
            while ($row=mysqli_fetch_array($result))
            {
               header("content-type: image/jpeg");
               echo $row['content'];
               

            }
            
    }
      ?>



Another thing is in gallery.html file the Html part is properly executed but it doesnt transfer control to gallery.php.
I tried to extract from the array the other fields like size,name id. It also dont work.
thanks for the help in advance
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Wed 04 Mar '09 23:29    Post subject: Reply with quote

it would be much easier if you only store the path in the db and the images themself in the file system.
But back to your code

snip
Code:

while ($row = mysqli_fetch_array($result)) {
echo '<img src="your.php?picture_name='. $row['picture_name'] .'" />';
}


snip
Code:

<?php
$name=mysql_real_escap_string($_GET['picture_name']);
$sql = "select * from upload WHERE `name`='$name';";
   
                 $result = mysqli_query($link,$sql) or die ("Could not access DB: " . mysqli_error());
header("content-type: image/jpeg");
echo $row['content'];
?>
Back to top
peacemaker



Joined: 23 May 2008
Posts: 80

PostPosted: Mon 29 Jun '09 12:36    Post subject: Hi Reply with quote

Hi James sorry for not replying to this reply of yours, actually i did the same thing u told me to do. I stored the paths of the images in the table and images into a folder. thanks for that.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1