By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

problem with display images

100+
P: 118
Hi,

I write the code to display images.But it will not display image.And also gives the error like that

error : Notice: Undefined index: gim in F:\Facebook\pic_up.php on line 59

plz tell that what is the problem in that code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Connect to database
  4.  
  5. $errmsg = "";
  6. if (! @mysql_connect("localhost","root","root")) {
  7.         $errmsg = "Cannot connect to database";
  8.         }
  9. @mysql_select_db("rainlist");
  10.  
  11. // First run ONLY - need to create table by uncommenting this
  12. // Or with silent @ we can let it fail every sunsequent time ;-)
  13.  
  14. $q = <<<CREATE
  15. create table pix (
  16.     pid int primary key not null auto_increment,
  17.     title text,
  18.     imgdata blob)
  19. CREATE;
  20. @mysql_query($q);
  21.  
  22. // Insert any new image into database
  23.  
  24. if ($_REQUEST['completed'] == 1) {
  25.         // Need to add - check for large upload. Otherwise the code
  26.         // will just duplicate old file ;-)
  27.         // ALSO - note that latest.img must be public write and in a
  28.         // live appliaction should be in another (safe!) directory.
  29.         move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
  30.         $instr = fopen("latest.img","rb");
  31.         $image = addslashes(fread($instr,filesize("latest.img")));
  32.         if (strlen($instr) < 149000) {
  33.                 mysql_query ("insert into pix (title, imgdata) values (\"".
  34.                 $_REQUEST['whatsit'].
  35.                 "\", \"".
  36.                 $image.
  37.                 "\")");
  38.         } else {
  39.                 $errmsg = "Too large!";
  40.         }
  41. }
  42.  
  43. // Find out about latest image
  44.  
  45. $gotten = @mysql_query("select * from pix order by pid desc limit 1");
  46. if ($row = @mysql_fetch_assoc($gotten)) {
  47.         $title = htmlspecialchars($row['title']);
  48.         $bytes = $row['imgdata'];
  49. } else {
  50.         $errmsg = "There is no image in the database yet";
  51.         $title = "no database image available";
  52.         // Put up a picture of our training centre
  53.         $instr = fopen("latest.img","rb");
  54.         $bytes = fread($instr,filesize("latest.img"));
  55. }
  56.  
  57. // If this is the image request, send out the image
  58.  
  59. if ($_REQUEST['gim'] == 1) {
  60.         header("Content-type: image/jpeg");
  61.         print $bytes;
  62.         exit ();
  63.         }
  64. ?>
  65.  
  66. <html><head>
  67. <title>Upload an image to a database</title>
  68. <body bgcolor=white><h2>Here's the latest picture</h2>
  69. <font color=red><?= $errmsg ?></font>
  70. <center><img src=?gim=1 width=144><br>
  71. <b><?= $title ?></center>
  72. <hr>
  73. <h2>Please upload a new picture and title</h2>
  74. <form enctype=multipart/form-data method=post>
  75. <input type=hidden name=MAX_FILE_SIZE value=150000>
  76. <input type=hidden name=completed value=1>
  77. Please choose an image to upload: <input type=file name=imagefile><br>
  78. Please enter the title of that picture: <input name=whatsit><br>
  79. then: <input type=submit></form><br>
  80. <hr>
  81. By Graham Ellis - <email removed>
  82. </body>
  83. </html>
  84.  
Jun 7 '08 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
The array index 'gim' doesn't exist.

Make sure you have it set to the right name.

Also, use code tags!
Jun 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.