Jump to content

Archived

This topic is now archived and is closed to further replies.

dandandan

Check if file existes

Recommended Posts

whats a function/way that i can check if a file exists? eg:

$number="1";
$filename="test";

untill (A FILE NAMED $filename$number.txt DOES NOT EXIST) {
$number++
}


Thats main idea of what i want to use it for, i just dont know what function to use.

Share this post


Link to post
Share on other sites
though you would want to add some code in there to do something to the file because the example will add indefinately.....

Share this post


Link to post
Share on other sites
I don't think it will.  It will not do anything, but it will not be an infinite loop.  It will add until the file doesn't exist, doing nothing each time. 

Share this post


Link to post
Share on other sites
slight modification to your code Timbo:

[code=php:0]
<?php
$number="1";
$filename="test";

while(!file_exists($filename.$number.'.txt'))
{
    $number++;
}
?>
[/code]

you forgot the ! in the condition, and a . between your $filename and $number, and also forgot some quotes for the .txt

Share this post


Link to post
Share on other sites
Actually, the ! shouldn't be there.  I think they wanted to do something to all files until they don't exist anymore.  But I did forget the .

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.