0

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?

Edited by cloud09: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by cloud09
0

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);
 
?>
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.