Closed Thread
Page 5 of 22 FirstFirst ... 3456715 ... LastLast
Results 41 to 50 of 214

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

  1. #41
    sanyal is offline Newbie
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

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

    thanx........for u r reply......... orjan

    but i could not get u .......
    to put the below script and call the fetch.php page.........as it will b feching images with respective 'id'......

    your code.........

    similar to this:
    PHP Code:

    Code:
    $query mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while(
    $row mysql_fetch_array($query)){
        
    $id $row[id];
        echo 
    "<img src='fetch.php?id=$id'>";
        echo 
    $row[comment];

    i tryed it .........i am able to get only image icons.........but not the images in the web page

    here is my code
    all_imgs.php =======>from this page i am calling fetch.php

    Code:
    <?php
    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 mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while(
    $row mysql_fetch_array($query))
    {
        
    $id $row[id];
        echo 
    "<img src='fetch.php?id=$id'><br>";
        echo 
    $row[comment];
    }  
        
    ?>
    //===============================================
    and here is the
    code for fetch .php (.........your 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';}
    ?>
    can u post the whoe code.........
    and how can i show the id,title,img .........all at one place from the img table
    which fields say as imagestable (id,title,img,description)

    thax in advance
    Last edited by Jaan; 12-21-2008 at 04:03 AM. Reason: Please use code tags when you're posting your codes!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #42
    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

    Too tired right now to post full codes. But no, it's not possible to do everything from one file.

    you need one php to show the pictures, and another one to create the html-page that includes the pictures.

    the php-file to show the pictures is in full shown in the first posting with the tutorial.
    the other php-file where you read out the surrounding data is built after how you want it. but in general, it's where you read out everything from the database but the picture itself.

  4. #43
    Talkabout is offline Newbie
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

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

    when i'm trying to show images, i got something like this:
    h t t p : / / img156.imageshack.us/my.php?image=imagerf8.jpg (remove spaces, i'm new here and not able to post links, but there is what i get)
    i really don't know what's the problem
    my code is:
    Code:
    <?php

    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientific";

    @
    mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());

    @
    mysql_select_db($database) or die("Can not select the database: ".mysql_error());

    $id $_GET['id'];

    if(!isset(
    $id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM article WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['photo'];

    header('Content-type: image/jpg');
    echo 
    $content;
    }
    ?>
    please help me
    Thanks

  5. #44
    Jaan Guest

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

    You get that.. because I don't know why..
    This is wierd.. It should display this:
    Code:
    die("Please select your image!"); 

  6. #45
    Talkabout is offline Newbie
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

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

    Quote Originally Posted by Jaan View Post
    You get that.. because I don't know why..
    This is wierd.. It should display this:
    Code:
    die("Please select your image!"); 
    well.. i tried another way. so in this way image should be displayed.. but it doesn't! and i really don't know why
    here is the code:
    form.html
    Code:
    <head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>add pic</title>
    </
    head>
    <
    body>
    <
    form action="insert.php" method="post" enctype="multipart/form-data" name="changer" >
    <
    input name1="MAX_FILE_SIZE" value="102400" type="hidden">
    <
    input name="image" accept="image/jpg" type="file">
    <
    input value="Submit" type="submit">
    </
    form>
    </
    body>
    </
    html
    insert.php

    Code:
    <?php 
    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientifc";

    // Make the connect to MySQL or die
    // and display an error.
    $link mysql_connect($host$username$password);
    if (!
    $link) {
        die(
    'Could not connect: ' mysql_error());
    }

    // Select your database
    mysql_select_db ($database);  


    // Make sure the user actually 
    // selected and uploaded a file
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

          
    // Temporary file name stored on the server
          
    $tmpName  $_FILES['image']['tmp_name'];  
           
          
    // Read the file 
          
    $fp      fopen($tmpName'r');
          
    $data fread($fpfilesize($tmpName));
          
    $data addslashes($data);
          
    fclose($fp);
          

          
    // Create the query and insert
          // into our database.
          
    $query "INSERT INTO article ";
          
    $query .= "(title,text,domain_id, photo,validat) VALUES ('sdfdsdfsds','ssdafdfg',3,'$data',1)";
          
    $results mysql_query($query$link);
          
          
    // Print results
          
    print "Thank you, your file has been uploaded.";
          
    }
    else {
       print 
    "No image selected/uploaded";
    }

    // Close our MySQL Link
    mysql_close($link);
    ?>
    and printimage.php

    Code:
    <?php
    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientific";

    @
    mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());

    @
    mysql_select_db($database) or die("Can not select the database: ".mysql_error());

    //$id = $_GET['id'];


    $id 22// just a test id to see if it works!

    if(!isset($id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM article WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['photo'];

    header('Content-type: image/jpeg');
    echo 
    $content;
    }
    ?>
    record with id 22 contains an image, in the column photo
    where the f... is the problem ?

  7. #46
    Jaan Guest

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

    Well.. Do you have a table called a "photo" ? or something.. I believe it don't get dat pic from the database, that's why it don't work..

  8. #47
    namhungsw28 is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

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

    thanks for your tutorial!

  9. #48
    jpresch is offline Newbie
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

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

    it just downloads the show.php to my HD automatically for me. But dude, I am totally new to php and creating databases as of well...... an hour ago. Got the database working and I can see there are several BLOBS that got created. I assume those are the images but not sure how to actually view them in the browser window.
    Last edited by jpresch; 01-23-2009 at 08:31 PM.

  10. #49
    jpresch is offline Newbie
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

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

    LOL....You actually have to display it in an html page....WORKS Perfect! Thanks you rock. good tut, if I can figure it out with no previous experience you did well my man.

  11. #50
    pkincses is offline Newbie
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

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

    Hi guys

    My problem is similar to what was mentioned before:image is displayed as a raw file...I tried to remove all the html info that were before and after the php tags but didn't do the trick.Here is the code, hope one of you might be able to help.Thanks in advance...

    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>';
     } 
     
    ?>
    Last edited by Jaan; 02-02-2009 at 07:50 AM. Reason: Please use code tags when you're posting your codes!

Closed Thread
Page 5 of 22 FirstFirst ... 3456715 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 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