I am working on a picture gallery management system for a website. I have the dynamic gallery done, and I am nearly done with the part that edits the gallery. However I have run into problem that no matter what I try doesn't want to go away.

When the user chooses pictures and uploads them, they choose where they want the pictures to be in the gallery(i.e. at the beginning, at the end, or replace the existing pictures). The script copies the files, and then includes another php file to edit the .INI file that controls how the pictures appear in the gallery. The problem is, is that when I create an array from the new files that were uploaded, and I try to put their names from the array into a variable, the names of the files always come first and then everything else (\n s, or even another piece that is concatenated before the file names).

<?php

$a = 0;

if($handle = opendir('./images/new_images')) {
  while(false !==  ($file = readdir($handle))) {
    if(trim($file != '.')) {
    if(trim($file != '..')) {
    echo $nfile[] = $file;
    }
  }
  }
}

foreach($nfile as $key => $value)
  {
  $add .= "$file[$a]\n";
  $a = $a + 1;
  }
  
$add1 = "[PICTURES]\n";

$INIadd = $add1 . $add;
  
echo $INIadd;
closedir($handle);

?>

The "echo $INIadd" outputs this:
0=file.png1=file2.png[PICTURES]

and if I put <br/>s after the nfile[$a] then they come after the file names and the files appear right next to each other on the same line.

Also is there a way to eliminate the the "." and ".." files that appear when you loop through the directory besides what I have done?

Try this.

<?php
 
$a = 0;
 
if($handle = opendir('./images/new_images')) {
  while(false !==  ($file = readdir($handle))) {
    if(trim($file,"\r\n\t/\\")!= '.' && trim($file,"\r\n\t/\\")!= '..') {
    echo $nfile[] = $file;
    }
  }
}
 
foreach($nfile as $key => $value)
  {
  $add .= $value."\n";
  $a = $a + 1;
  }
 
$add1 = "[PICTURES]\n";
 
$INIadd = $add1 . $add;
 
echo $INIadd;
closedir($handle);
 
?>

I figured out what the problem was with the help of the code that you gave me - I forgot I echoed the value of the files earlier in the script without any formatting, which is now removed, and my script fully functional. Thank You.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.