Closed Thread
Page 17 of 22 FirstFirst ... 71516171819 ... LastLast
Results 161 to 170 of 214

Thread: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  1. #161
    sami221987 is offline Newbie
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    But how insert.php and another page which contain second code to retrieve image from database is connected
    can u plz expalin me

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #162
    k1net1cs is offline Newbie
    Join Date
    Oct 2009
    Posts
    20
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Quote Originally Posted by pages View Post
    if i remove header('Content-type: image/jpg');
    I see the persons details but for the image i only see raw data .
    That's because you executed print() before header().
    The header() function should never be executed after any functions that's intrinsically sends a header like print() or echo().

    Try reading this post of mine on previous pages for a user who had a similar problem as yours.
    And on this thread page is the original breakdown of what I came up to store and display the image.

    Sorry for the late reply, but HTH.
    Last edited by k1net1cs; 05-07-2010 at 11:47 AM. Reason: forum's url parsing fail... -_-;

  4. #163
    qakbar is offline Newbie
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Jaan,

    Can you please help me with a little query I have. I want to be only show thumbnails of the images and not a full image on the page. How can that be achieved with a little caption at the bottom of the picture to say the person's name??

    I am a newbie to programming and any help you provide is much apprecaited.
    my email is qakbar@hotmail.co.uk
    Thank you

  5. #164
    keyngosh is offline Newbie
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    HI,

    I need to display images in a table and resize the images ho do i do this?

  6. #165
    lrearth is offline Newbie
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi

    I used same code... But did not get image. It is showing cross instead of image...


    Code:
    Code:
    <?
    if(isset($_GET['id']))
    {
    header('Content-type: image/jpeg'); // act as a jpeg file
        
    mysql_connect('localhost','root','')or die(mysql_error());
        @
    mysql_select_db('test')or die(mysql_error()); // use the ‘test’ database

        
    $query 'select * from images where id = $id';
        
    $result mysql_db_query('test',$query)or die(mysql_error());

        
    $row mysql_fetch_array($result);
        
    $img $row['img'];

        echo (
    $img);
        }
        else{echo 
    'id is not send';}
    ?>
    Last edited by Jaan; 07-09-2010 at 04:25 PM. Reason: Please use code tags when you are posting your codes!

  7. #166
    lrearth is offline Newbie
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi guys

    My problem is I have loaded image into data base, but when I was trying to get this, it was showing cross....

    Code:
    Code:
    <?php
    
    echo "<p>Recent uploads</p>";
    // Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'root');
    if (!$dbcnx) {
     exit('<p>Unable to connect to the ' .
         'database server at this time.</p>');
    }
    
    
    // Select the pictures database
    if (!@mysql_select_db('pictures')) {
     exit('<p>Unable to locate the Pictures ' .
         'database at this time.</p>');
    }
    
    
    
    // Request the id, title, img of files
    $result = @mysql_query('SELECT id, title, images FROM details');
     if (!$result) {
       exit('<p>Error performing query: ' .
           mysql_error() . '</p>');
     } 
    
    // Display $result in a paragraph
     while ($row = mysql_fetch_array($result)) {
       $id = $row['id'];
       $title = $row['title'];
       $img = $row['images'];
       
       header('Content-type : image/jpg');
       echo '<blockquote>' . $id, $title, $img .'</blockquote>';
     } 
     
    ?>

  8. #167
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    lrearth, as answer to you, as to just about everyone here (if you have read the thread you'd know) you can't put any other code into the show.php file! it has to be exactly as it was written. it needs to be stand alone and to be called upon as it was a image file on disk, like <img src="show.php?id=12">
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  9. #168
    lrearth is offline Newbie
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi,
    I used this code -

    Code:
    <?php
    
     if($_GET['id']) {  
    	 
    	 $id = $_GET['id']; 
    
        if (! @MYSQL_CONNECT("localhost","root","sslmtk13")) {
        print "Cannot connect to database";
        } 
         
    	 print "Id = $id";
        @mysql_select_db("test");
    
        $query = "select bin_data,filetype from binary_data where id='$id'";
        $result = @MYSQL_QUERY($query) or die('Bad query at 12!'.mysql_error());
    
        $data = @MYSQL_RESULT($result,0,"bin_data");
        $type = @MYSQL_RESULT($result,0,"filetype");
    
        Header( "Content-type: $type");
        echo $data;
    
    } else {
    print "No Id";
    }
    
    ?>
    I tried url this - http://localhost/kabaap/getImage.php?id=10

    I got output -

    Code:
    http://localhost/kabaap/getImage.php?id=10

  10. #169
    IslesofWight is offline Newbie
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Upload code:

    Code:
    <?php
    $q=$_GET["q"];
    
    $con = mysql_connect("****************************************");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("aarclients", $con);
    ?>
    <form method="post" enctype="multipart/form-data">
    <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr>
    <td width="246">
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
    <input name="userfile" type="file" id="userfile">
    </td>
    <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
    </tr>
    </table>
    </form>
    <?php
    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    if(!get_magic_quotes_gpc())
    {
      $fileName = addslashes($fileName);
    }
    $query = "INSERT INTO upload (name, size, type, content ) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$q')";
    mysql_query($query) or die('Error, query failed');
    echo "<br>File $fileName uploaded<br>";
    }
    ?>
    Display code:

    Code:
    <?php
    
    $con = mysql_connect("*******************************");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("aarclients", $con);
    
    $id = $_GET['id'];
    
    if(!isset($id) || empty($id)){
    die("Please select your image!");
    }
    else{
    
    $query = mysql_query("SELECT * FROM upload WHERE debtor_id='".$id."'");
    $row_image = mysql_fetch_array($query);
    $content = $row_image['content'];
    $filetype = $row_image['type'];
    
    header("Content-type: $filetype");
    
    echo $content;
    
    }
    
    ?>
    All im getting is blank page..

  11. #170
    pravin3009 is offline Newbie
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    hello Jaan, I am trying similar things as you explained above, but the image is not getting display on the page, it shows the place holder on the page with a samll cross mark at the top. here is my code
    I am a beginner in php, so if I am missing any reference, please let me know.

    the page which is displaying the image -
    HTML Code:
    <html>
     <head>
      <style type="text/css">
       .background { background-image:url(back.png);background-repeat:repeat-x; }
    </style>
      <title>PHP Test</title>
     </head>
     <body>
     <div Class="background">
      <table style="width:100%; height:100px;">
         <tr>
           <td width="100%" align="center" height="100px">
            <!-- Banner -->
             My Page
          </td>
        </tr>
       </table>
        <table style="width:100%; height:100px;">
         <tr>
           <td>
             <!-- Image1   --> 
             <img src="getImage.php" height="100px" width="70"/>           
             
           </td >
           <td width="30%" style="height:100px;">
             <!-- Image2 -->        
           </td>
           <td width="30%" style="height:100px;">
             <!-- Image3 -->
             image 3
           </td>
         </tr>
         </table>
      </div>
     </body>
    </html>
    and the page which is retrieving he image -
    Code:
    <?php 

    mysql_connect
    ("localhost","root","mysql") or die("Unable to connect to SQL server"); 
    @
    mysql_select_db("database") or die("Unable to select database"); 
    $result=mysql_query("select * from table_name where rowid=1") or die("Can't perform Query"); 

    $data=@MYSQL_RESULT($result,0,"content_image"); 

    header('Content-Length: '.strlen($data));
    header('Content-Disposition: inline; filename="add1.jpg"'); 
    header('Content-type: image/jpg'); 
    echo(
    $data);  

    ?>
    your response is highly appriciated..
    Last edited by Jaan; 08-03-2010 at 03:31 AM. Reason: Please use code tags when you are posting your codes!

Closed Thread
Page 17 of 22 FirstFirst ... 71516171819 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  2. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 47
    Last Post: 01-04-2011, 08:37 PM
  3. Beginner Storing images in XML file - Part II - Displaying image
    By Jaan in forum PHP Tutorials
    Replies: 6
    Last Post: 01-04-2011, 08:35 PM
  4. display images sequentially using PHP and MySQL
    By jhanjon in forum PHP Development
    Replies: 2
    Last Post: 10-08-2009, 12:11 PM
  5. Replies: 2
    Last Post: 07-16-2009, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts