dandandan Posted October 5, 2006 Share Posted October 5, 2006 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. Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/ Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 I would try the file_exists() function Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104144 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 [code]<?php$number="1";$filename="test";while(file_exists($filename$number.txt)){ $number++;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104145 Share on other sites More sharing options...
markbett Posted October 5, 2006 Share Posted October 5, 2006 though you would want to add some code in there to do something to the file because the example will add indefinately..... Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104147 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 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. Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104148 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 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 Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104153 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 yes, thank you. Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104160 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 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 . Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104161 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 okay yes you are right about the ! Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104168 Share on other sites More sharing options...
dandandan Posted October 5, 2006 Author Share Posted October 5, 2006 thanks guys, twas a great help. Its up and working now Link to comment https://forums.phpfreaks.com/topic/23054-check-if-file-existes/#findComment-104176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.