Jump to content

adding to MySQL image from dir list, no reaction no error


Peuplarchie

Recommended Posts

Good day to you all,

                    I'm trying to read a directory and for each file add : path, name, ext, width and height to my database.

 

 

Right now the only thing I had succeed in to list the image directory.

 

 

I have tried out to add it to the database but no reaction, nothing is added to the db, no error ?

 

Here is my code:

 

  <?php


// Connect to database


$con = mysql_connect("localhost","111",111");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("images", $con);


  
  $imgdir = 'Images/'; // the directory, where your images are stored
  $realimgdir = "Images/";
  $allowed_types = array('png','jpg','jpeg','gif','bmp'); // list of filetypes you want to show
  
  $dimg = opendir($imgdir);
  while($imgfile = readdir($dimg))
  {
   if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
   {
    $a_img[] = $imgfile;
    sort($a_img);
    reset ($a_img);
   }
  }
  
  $totimg = count($a_img); // total image number
   
  for($x=0; $x < $totimg; $x++)
  {
   $size = getimagesize($imgdir.'/'.$a_img[$x]);
  
   // do whatever
   $halfwidth = ceil($size[0]/2);
   $halfheight = ceil($size[1]/2);

$rid = $realimgdir;
$fname = substr($a_img[$x],0, -4);
$extens = substr($a_img[$x], -3);
$iwidth = $size[0];
$iheight = $size[1];

   
mysql_query("INSERT INTO gallery (id, path, name, ext, width, height)
VALUES ('$rid', '$fname', '$extens', '$iwidth', '$iheight'");  

   echo '<tr title="'.$a_img[$x].'" onMouseOver="this.className=\'highlight\'" onMouseOut="this.className=\'normal\'"></td><td>'.$realimgdir.'</td><td>'.substr($a_img[$x],0, -4).'</td><td style="text-align:center;"> '.substr($a_img[$x], -3).' </td><td style="text-align:center;"> '.$size[0].' </td><td style="text-align:center;"> '.$size[1].'</td></tr>';
  }
  
  ?>
</table> 

 

Somebody have an idea

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.