Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    readdir write names to Mysql

    Hello

    I use this Code to List Files in My director .. I need to inser the Name of the Files into Mysql ..

    How So ..this wht i tried and did not work ..

    PHP Code:
    $dir 'images/';
    if (
    $dh opendir("$dir")) {
           
    $files = array();
           while ((
    $file readdir($dh)) !== false)         {
         if (
    $file == "." or $file == ".." or $file == "Thumbs.db" or $file == "index.php" or $file == "index.html" ){
          continue;         }
                 
    $files[] = $file; }
                 
    $files_num=count($files);
                  echo 
    " we found".$files_num." file<br><hr>";
                 
    $counter=0;
                while(
    $counter<$files_num){
             echo
    " $files[$counter]<br>";
             
    $counter++;
            } }
            
    ///
      
    $sql "INSERT INTO test_tble (title) VALUES ('$files[$counter]')";
    $ret mysql_query($sql);

      if (!
    $sql){
    echo 
    "<center>err</center>";
      }else{
    echo 
    "<center>ok</center>";
        } 

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Well i would do it like this :

    PHP Code:
    $directory='./images/';
        
    $results = array();
        
    $handler opendir($directory);

        while (
    $file readdir($handler)) {

            if (
    $file != '.' && $file != '..')
                
    $results[] = $file;
        }

    foreach(
    $results as $key => $val){
      
    $sql "INSERT INTO test_tble (title) VALUES ('$val')";
    $ret mysql_query($sql); 


  • Users who have thanked Killermud for this post:

    ajloun (02-21-2010)

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Great .. Works well ..
    I kinda wanted to list the Files names too ..and be able to click Go before insert it .. i will try do it myself .. and hope i get it ..if not i will Update this Topic


  •  

    Posting Permissions

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