Closed Thread
Page 13 of 22 FirstFirst ... 31112131415 ... LastLast
Results 121 to 130 of 214

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

  1. #121
    helena is offline Newbie
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

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

    Hi ..

    thanks for your reply.. but now i face a new issue it when i go show.php
    it opens as attachment no picture is viewed
    please resolve this issue
    thanks

    please check

    st-michaelsacademy.com/show.php

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

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

    @helena :

    The page shows the image just fine.
    Try accessing the page with the id numbers, like this :

    st-michaelsacademy.com/show.php?id=3

  4. #123
    Jaan Guest

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

    http://st-michaelsacademy.com/show.php?id=1
    works fine for me..



    i used:

    Code:
    [IMG ]http://st-michaelsacademy.com/show.php?id=1[/IMG]

  5. #124
    tayolad is offline Newbie
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

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

    jaan, thanx for this tutorial, however, i have a DB with a table like this, employee_id,employee_name,employee_picture. I want to display the pictures with the corresponding name in a table. ow do i do that?
    thank you for your time.

  6. #125
    Jaan Guest

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

    Hmm..
    you can do it like this

    Code:
    $name $_GET['name'];
    $sql "SELECT employee_picture FROM table_name WHERE employee_name='".mysql_real_escape_string($name)."'";
    $query mysql_query($query);
    $row mysql_fetch_array($query);

    $image $row['employee_image']; 
    or something like that.. try this

  7. #126
    tayolad is offline Newbie
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

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

    thanx jaan. But it didnt work. It brought out unreadable characters in the picture column of the table. Please assist.

  8. #127
    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

    Did you store the image as a BLOB type?

    If you did, did you 'send' the image from your database with a correct header?
    Or, did you use a separate PHP for fetching the images?

  9. #128
    Jaan Guest

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

    Kinetics is right, your image have to be "BLOB" in database and also when you are displaying your image you must define correct header

  10. #129
    tayolad is offline Newbie
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

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

    thanx everyone. YES, the image column is blob type. This is the complete script. Please check it out.

    Code:
    <?php 
    if(isset($_POST['submit1']) || !empty($_POST['submit1']) && !empty($_POST['txtID']) && $_FILES['userfile']['size'] > 0)
    {
     
    $msg=array();
     
    $ref_db="";
     
    $green_flag=0;
     
    $the_staffid=$_POST['txtID'];
     
    $ref_db="mydbsr";
     
    $dbcon=funcReadWriteConn();
     if(!
    $dbcon){
      echo
    "<br />Could Not connect to the database, please try again later";
      die();
     }
     
    $row_no=0;
     
    $dbid=mysql_select_db($ref_db,$dbcon);
     
    $query="";
     
    $query="SELECT rtype FROM pixtable WHERE ucase(trim(rstaffid))='".strtoupper(trim($the_staffid))."'";
     
    $rst=mysql_query($query,$dbcon);
     if(
    $rst$row_no=mysql_num_rows($rst);
     if(
    $row_no>0){      
        
    $msg[]="<font color=red><br />Sory, this Picture has been previous uploaded, Pictures cannot be changed by you.";
        
    mysql_free_result($rst);
        
    mysql_close($dbcon);
        
    $green_flag=0;
     }
     if(
    $row_no<=0)//i.e pix has NOT been previous uploaded
     
    {
      
    $green_flag=1;
      
    $fileName $_FILES['userfile']['name'];
      
    $tmpName  $_FILES['userfile']['tmp_name'];
      
    $fileSize $_FILES['userfile']['size'];
      
    $fileType $_FILES['userfile']['type'];
      
    $msg[]="File Sie:".$fileSize." File Type:".$fileType;
      if(
    $fileSize==0) { 
        
    $msg[]="<font color=red><br />No fle selected expecting maximum of 20KB."
        
    $green_flag=0;
      }  
      if(
    $fileSize>20000) { 
        
    $msg[]="<font color=red><br />Sorry, your file is too big (".$fileSize."Bytes) expecting maximum of 20KB"
        
    $green_flag=0;
      }
      if(
    $fileType==''){ 
        
    $msg[]="<font color=red><br />Your file type is NOT known, configure your browser properly or use Firefox/IE 6 and above."
        
    $green_flag=0;
      }  
      if(
    $fileType!='image/jpeg'){ 
        
    $msg[]="<font color=red><br />Sorry, your file type is (".$fileType.") expecting jpeg type."
        
    $green_flag=0;
      }
      if(
    $green_flag==1)
      {
       
    $fp fopen($tmpName'r');
       
    $content fread($fpfilesize($tmpName));
       
    $content addslashes($content);
       
    fclose($fp);
       if(
    get_magic_quotes_gpc()) $fileName stripslashes($fileName);
       
    $fileName=mysql_real_escape_string($fileName,$dbcon);
       
    $query "INSERT INTO pixtable (rstaffid, rsize, rtype, rpix ) VALUES ('$the_staffid', '$fileSize', '$fileType', '$content')";
       
    $ret=mysql_query($query,$dbcon);
       if(!
    $ret) die("Sorry, Could NOT upload");
       if(
    $ret) {$msg[]="<font color=red><br />Your Picture has been uploaded";$saved_flag=1;}
      }
    //green_flag=1  
      
    mysql_close($dbcon); 
     }
    //row<0
    }
    ?>
    I checked the table and the blob column has values. I tried to display and to no avail.I need to display it in a table pix|staffid|name. The name and other information are kept in another table.
    Thanx.
    Last edited by Jaan; 01-19-2010 at 03:46 PM. Reason: Please use code tags when you are posting your codes!

  11. #130
    tayolad is offline Newbie
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

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

    I mean that i need to display in an HTML table with the following column pix|staffid|name|other_info. The name and other info are saved in another mysql table separate from the mysql pixtable.

Closed Thread
Page 13 of 22 FirstFirst ... 31112131415 ... 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