I've searched for this for quite a while now and I cannot figure out why my code isn't working how it appears. I'm not sure if I'm having a block or anything but here goes:
$start = 1;
$sstart = strval($start);
$scan = scandir('upload');
$result = null;
while($result==null)
{
foreach($scan as $value)
{
if(strpos($value,$start) == false)
{
$result = $start;
break 2;
}
else
{
$start = $start + 1;
break;
}
}
}
Essentially, I want to scan my directory 'upload'
for any files with the number held in $start
. If this value ISN'T found, then $result
takes the value of $start
and the while()
loop ends. Otherwise I increment $start
and proceed to check every file in the directory again.
Now I have a very similar function like this running on another page that works flawlessly. However this always seems to stop at 1.
There is DEFINITELY a file in my upload folder called showreel1.wmv
and it definitely scans this. (Have echo'd the scandir array) However, it never seems to switch to the else
block but carries on setting $result
as if it never found the value '1'.
I have also tried using $sstart
in the strpos()
function and it has no effect, this of course changes the value of $start
into a string.
Can you guys shed any light on this for me please?