+ Reply to Thread
Page 3 of 16
FirstFirst 1 2 3 4 5 13 ... LastLast
Results 21 to 30 of 158

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

  1. #21
    Newbie wendellrt is an unknown quantity at this point wendellrt's Avatar
    Join Date
    Sep 2008
    Posts
    2

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

    Hello Everyone.

    When I use the example code, all I get is a blank (all white) page being displayed in my browser ('view source' displays a blank page as well).

    Where did I go wrong???

  2. #22
    Newbie wendellrt is an unknown quantity at this point wendellrt's Avatar
    Join Date
    Sep 2008
    Posts
    2

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

    You could try putting the following...
    Code:
    header('Content-type: image/jpg');
    before the line which reads...

    Code:
    echo $content;
    HTH.
    Last edited by Jaan; 10-13-2008 at 01:36 PM. Reason: Please use code tags when you're posting your codes!

  3. #23
    Newbie casper3000ah is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    1

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

    thank you for ur effort

    thanks man

  4. #24
    Newbie billjones is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    3

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

    Hi , Jaan
    Can you help a newbie ?
    I can upload images into the database with no problems, but retrieving them is a problem, they come out of the database in a raw form, its as if the following code is not working !

    header('Content-type:image/jpg');

    it does not seem to have an effect, if I delete this part of the code I get the same result! Raw data. Can you help?
    Last edited by billjones; 10-13-2008 at 01:10 PM.

  5. #25
    Newbie billjones is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    3

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

    can anyone help with the above?

  6. #26
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,058
    Blog Entries
    9

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

    Umm.. do you use the same script or you have changed it..?

    If you have changed it, please post it here so I can check what's the problem
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  7. #27
    Newbie billjones is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    3

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

    Hi Jann,

    Thanks for the quick reply, here is my code.

    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>


    php code for the page insert.php


    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>insert</title>
    </head>
    <?php 

    // Create MySQL login values and 
    // set them to your login information.
    $username "abc";
    $password "123";
    $host "localhost";
    $database "test";

    // 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 tbl_images ";
          
    $query .= "(image) VALUES ('$data')";
          
    $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);
    ?>  

    <body>
    </body>
    </html>
    this works fine untill i try to get the pic out of the db......

    php code for print_pic.php

    Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php

    $username 
    "abc";
    $password "123";
    $host "localhost";
    $database "test";

    @
    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 1// 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 tbl_images WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['image'];

    header('Content-type: image/jpg');
    echo 
    $content;

    }

    ?> 
    </body>
    </html>
    I hope you can help.

    Thanks Bill.
    Last edited by Jordan; 11-09-2008 at 08:18 PM. Reason: added tags

  8. #28
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,607
    Blog Entries
    7

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

    please use the php tags.

    this is a special php file when you output the picture, it may not contain any html as it's a picture you're returning, not a web page.

    remove everything before <?php and after ?> and it will work. make extremely sure that there are absolutely no letters, spaces or any other symbols before the <?php otherwise, the system might believe it's a web page and goes nuts.

  9. #29
    Newbie anujphp is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    1

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

    hello
    thanks for the code its works fine for me but i have a problem..though the script work fine when i open my page in flock or mozilla or any toher browser but it dont work when i open the page in internet explorer..it try to download the php file....can you kindly solve my this problem....
    i am trying to open the file with this url
    localhost/test/displayimage.php=?1



    IT works fine with in flock and mozilla

  10. #30
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,058
    Blog Entries
    9

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

    your link must be..

    displayimage.php?id=1
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

+ Reply to Thread
Page 3 of 16
FirstFirst 1 2 3 4 5 13 ... LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 43
    Last Post: 01-16-2010, 10:35 AM
  2. Tutorial: PHP to MySQL
    By Jordan in forum PHP Tutorials
    Replies: 20
    Last Post: 08-28-2009, 04:22 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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