Hi,

I’ll use a txt file to store locations in it. When I user click on button, the locations will be read from txt file and stored in an array. If more than 1 user run this script, will it cause problem like “File is already open”? It this reliable.

Thanks

<?php
$myFile ='locations.txt';
$myArray = file ($myFile);
 
foreach($myArray as &$value) {
	insert into a combobox = trim($value);
}
unset($value);
?>

Recommended Answers

All 2 Replies

No that shouldn't cause such a problem, just remember the rules when working with files:

1. Only give users access to files that you want them to have access to. Use permissions to restrict read/write/execute on files. I would suggest making sure that users can only read your location file except in very rare circumstances, and never let them delete it.
and 2. Don't forget to close the file handle when you are finished with it. Bad things happen when you don't clean up after yourself.

Hi,
Thanks for your answers. According to your answers, also;

1. When first PHP page is loaded, it only populates info into combo. There is nothing to do with users. Therefore, this should be safe enough. Is this right?
2. Do i need to add anything else to close or clean things after? If yes please state. I'll be happy.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.