TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-29-2010, 11:49 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application adding to MySQL image from dir list, no reaction no error

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 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 (idpathnameextwidthheight)
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
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 07-01-2010, 03:13 AM   #2 (permalink)
The Visitor
 
Join Date: Jun 2010
Posts: 1
Thanks: 0
nonggiatu is on a distinguished road
Default

You should catch the exception when working with DB and see if something is wrong. Maybe two reasons:
1. If the ID field is "auto increment", you should not specify the ID value to insert.
2. Is possible that there were two equal IDs ?
nonggiatu is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Reflections in PHP Rendair Advanced PHP Programming 17 11-30-2011 08:41 AM
MySQL Server error #2003(HY000): Can't connect to MySQL Server on 'localhost'(10061) Yoosha MySQL & Databases 3 06-15-2009 02:45 PM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
Adding Images to a database from a folder Rendair Advanced PHP Programming 3 01-13-2008 07:40 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM


All times are GMT. The time now is 11:14 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design