RE: [PHP] Re: Replacing datafile with array
| From: | Daniel Alsén | Date: | Tue, 18 Sep 2001 11:41:31 +0000 |
| Subject: | RE: [PHP] Re: Replacing datafile with array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67698@lists.php.net to get a copy of this message | ||
Hmm...
it still doesn´t work.
If i echo $retVal i just get the word 'Array' (the same number of times that
the number of files in the directory).
If i echo $file i get the file listing...however, it doesn´t pass on the
content to the rest of my script.
Maybe someone could help me out with the whole script? I downloaded this
from some script archive and it works if i use the list.photos datafile. But
i don´t want to change that file every time a new photo is uploaded.
I am trying to read the directory and use the directory handle listing
instead.
If anyone wants to help me out making this databasedriven instead youre very
welcome :)
<?PHP
$retVal = array ();
//Load Directory Into Array
$handle=opendir('.');
while (false !== ($file = readdir($handle)))
if ($file != "." && $file != ".." &&
ereg(".jpg",$file)) {
$retVal [count($retVal)] = $file;
echo "$retVal <br>\n";
}
//initialize variables
//$data_file = "list.photos";
$thumbnail_dir = "thumbs/";
$num_rows = 3;
$photos_per_row = 3;
$photos = file($retVal); //$retVal used to be $data_file
$total_photos = sizeof($photos);
$photos_per_page = $num_rows * $photos_per_row;
//check to see if the start variable exists in the URL.
//If not, then the user is on the first page - set start to 0
if(!isSet($start)){
$start = 0;
}
//init i to where it needs to start in the photos array
$i = $start;
$prev_start = $start - $photos_per_page;
$next_start = $start + $photos_per_page;
for ($row=0; $row < $num_rows; $row++){
print("<tr>\n");
for ($col=0; $col < $photos_per_row; $col++){
if($i < $total_photos){
$thumbnail = $thumbnail_dir.trim($photos[$i]);
$thumb_image_size = getimagesize($thumbnail);
$image_size = getimagesize(trim($photos[$i]));
print("<td align=\"center\">
<a
href=\"javascript:photo_open('photo_display.php?photo=".trim($photos[$i])."'
,'".$image_size[0]."','".$image_size[1]."');\"><img
src=\"".$thumbnail."\"
".$thumb_image_size[3]." border=\"0\"></a></td>\n");
} else {
print("<td></td>\n");
}
$i++;
}
print("</tr>\n");
}
//Clean up directory array
closedir($handle);
return $retVal;
//end table
?>
> -----Original Message-----
> From: _lallous [mailto:elias_bachaalany@yahoo.com]
> Sent: den 18 september 2001 13:46
> To: php-general@lists.php.net
> Subject: [PHP] Re: Replacing datafile with array
>
>
> works like a charm....
>
> just initializet the $retVal function...
>
> $retVal = array();
> rest of script here....