Hi,
this was a general question: I don't know if what I did is wrong but I'm confused.
I am counting files in a directory so that people can't upload more than x number of files without deleting some.
What I have noticed is that the first time I upload a file '$count' is given as 1 (echoed).
The second time is also 1, then 2 etc.

I realised that I was counting the files BEFORE saving the new upload to the directory in question, so that explained why my echoes always were 1 behind the real value, but I cannot figure out why it says '1' the FIRST time, when the directory is empty.

If it was counting a 'hidden' file or something, wouldn't it carry on from there: 1,2,3.... Likewise, if it's counting the uploaded (but not saved) file?

My server is running on Linux, if that makes a difference.

I was thinking this might be a general knowledge type thing rather than the code. I haven't tried working with files before and there seems to be a lot I don't know.

here is the relevant part of my script if it helps ...


if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {

$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if ((($ext == "jpg") || ($ext == "gif") || ($ext == "png")) && (($_FILES["uploaded_file"]["type"] == "image/jpeg") || ($_FILES["uploaded_file"]["type"] == "image/gif") || ($_FILES["uploaded_file"]["type"] == "image/png")) &&
($_FILES["uploaded_file"]["size"] < 30000)) {

$newname = dirname(__FILE__).'/pictures/uploads/'.$venue.'/'.$filename;

if (!file_exists($newname)) {

$directory = 'pictures/uploads/'.$venue.'/';


$filecount = count(glob("" . $directory . "*"));

echo $filecount; ////THIS IS THE PART THAT ECHOES 1 TWICE


if ($filecount <= 11) {

if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
$new_query = "UPDATE venues SET Pic = '$filename' WHERE VenID = '$venue' LIMIT 1;";
$new_sql = mysql_query($new_query,$dbh);
if (!$new_sql) {
echo "<br />oops! can't change photo because - <br>";
die('Could not query:' . mysql_error());
exit;
}
else {
echo "<br />Your venue's photo has been changed.<br />";
}
echo "<br />The photo has been saved in your portfolio<br />";
}
else {
echo "<br />Error: A problem occurred during file upload!<br />";
}
}
else {
echo '<br />Error: there are already 12 photos in your portfolio. You can delete photos via View Portfolio.<br />';
}
}
else {
echo "<br />Error: File ".$_FILES["uploaded_file"]["name"]." already exists<br />";
}
}
else {
echo "<br />Error: Only .jpg .gif or .png images under 30KB are accepted for upload<br />";
}
}
else {
echo "<br />No file uploaded<br />";
}