spillage Posted April 10, 2008 Share Posted April 10, 2008 please help!!!! all i need to do is check a file exists before my main code runs. should it just be fopen("filename.txt) or exit; fclose("filename.txt); Probally a long way off but am new to this and find the learning curve steep. Thanks Link to comment https://forums.phpfreaks.com/topic/100492-simple-file-check-question/ Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Share Posted April 10, 2008 bool file_exists ( string $filename ) Please... at least use google next time. Link to comment https://forums.phpfreaks.com/topic/100492-simple-file-check-question/#findComment-513935 Share on other sites More sharing options...
spillage Posted April 10, 2008 Author Share Posted April 10, 2008 sorry zhadus should have been more specific. i need to have a check box option for deleting data on the same page and have got myself in a mix with unlink deleting the entire .txt file so the page refreshed and then showed and error because it cannot find the file. thought that by having this code in first i could stop this happening by possibly using an if function. although thinking of trying to open the file using just 'w' then closing again as im sure this will just clear all the data in the file. like i said im very new to this and still trying to get my head around allot of it. thanks Link to comment https://forums.phpfreaks.com/topic/100492-simple-file-check-question/#findComment-514067 Share on other sites More sharing options...
marcus Posted April 10, 2008 Share Posted April 10, 2008 w only opens the file for writing to a file, also attempts to create a file if it doesn't exist w+ opens for both reading and writing, and attempts to create a file if it doesn't exist $f = fopen('filename.txt','w+'); Link to comment https://forums.phpfreaks.com/topic/100492-simple-file-check-question/#findComment-514094 Share on other sites More sharing options...
spillage Posted April 10, 2008 Author Share Posted April 10, 2008 finally worked it out. it just needed $fp=fclose(fopen("$document_root/.txt",'w')); print 'file cleared' This just removes all data from the file but leaves the file intact. Thanks Link to comment https://forums.phpfreaks.com/topic/100492-simple-file-check-question/#findComment-514270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.