RE: [PHP] Comparing Arrays - mysql_query & readdir
| From: | Emile Axelrad | Date: | Mon, 03 Jul 2000 12:51:10 +0000 |
| Subject: | RE: [PHP] Comparing Arrays - mysql_query & readdir | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4478@lists.php.net to get a copy of this message | ||
> I have a mysql table containing the file names of thumbnail images used
> in a catalog.
> I want to compare those filenames with the actual files stored in the
> web server directory.
>
> So I use a mysql_query to create an array of the filenames from the
> database, and opendir/readdir to create an array of the directory
> filenames.
>
> What I would like to do is compare the arrays and list the files that
> are in the directory, but not in the database (so I know which images
> can be deleted from the directory).
>
> Any help?
How does this general code sound [I'm no PHP expert though...] so you'll
need to mess it about yourself
foreach ($filenames as $currentfile) {
$result = mysql_query("SELECT * FROM filenames WHERE
filename='$currentfile'");
if ($rs = mysql_fetch_array($result)) {
# This file is in the directory and the database
} else {
# This file is in the directory but not the database
echo "Deleteable: " . $currentfile;
}
}
[Have I missed the point...?]
- Emile Axelrad