reading random files from a folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freefony
    New Member
    • Nov 2008
    • 59

    reading random files from a folder

    i have a folder which pictures of candidates from all the states but i need to get pictures of candidates for one state and put them in another folder my database contains directory of all the files in the picture folder
    please help

    Code:
    //get the picture directory in an array
    $qry="select pix from corper";
    $rst=mysql_query($qry) or die (mysql_error());
    $num=mysql_num_rows($rst);
    while($r=mysql_fetch_assoc($rst)){
     $pix[]=$r["pix"];
    }
    for($file as $pix[]){
    // set file to read
    $file = 'picture/'.$pix[].;
    // open file
    $fh = fopen($file, 'r') or die('Could not open file!');
    // read file contents
    $data = fread($fh, filesize($file)) or die('Could not read file!');
    // close file
    fclose($fh);
    echo $data;
    }
    it not working please whats wrong
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    are the files being uploaded using a form? if so maybe within the pictures directory it should sort into the correct states folder on upload it would be alot easier.

    if not then you would be needing to have some indication in those file names to do with states so that they can be picked up on

    also this should have some indication of the array number but there maybe not be a need for the"[]" at the end try it without see if that helps

    Code:
    $pix[0]=$r["pix"];
    
    or
    
    $pix=$r["pix"];

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      if you need help you will have to post the majority of your code from start to finish so we can see your process

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Your code looks fine from my quick scan. No anfetienne, his array is fine, your code would break it.

        Just try printing $file and see what's inside it. Do a little debugging and tell us where the problem is, instead of just saying "IT doesn't Work" and run around with your hands in the air :)



        Dan

        Comment

        Working...