coolbeansdude51 Posted April 10, 2009 Share Posted April 10, 2009 Hello forum! Hope everyone is doing well. I have a question for your genius! All I want to do is make sure that: 1. That in the user_data folder there is a folder named userid. 2. If that's not there then it needs to be created. 3. It then needs to check for another folder inside of that folder. The month and year. 4. If that's not there then it needs to be created. 5. Once all of those are check then it needs to create a file inside of that folder. Here is my logic. I know that the code below doesn't work but .... anyone have any suggestions? $timestamp = time(); $month = date('m_Y', $timestamp); $userid = '71625181'; if(file_exists('user_data/'.$userid.'/'.$month)) { echo 'level 1'; $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); } else { echo 'level 2'; mkdir('user_data/'.$userid.'/'.$month); $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); } else { echo 'level 3'; mkdir('user_data/'.$userid); mkdir('user_data/'.$userid.'/'.$month); $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); } or I was thinking this if(file_exists('user_data/')){ echo 'level 1'; mkdir('user_data/'.$userid); mkdir('user_data/'.$userid.'/'.$month); $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); } elseif(file_exists('user_data/'.$userid)) { echo 'level 2'; mkdir('user_data/'.$userid.'/'.$month); $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); } else { echo 'level 3'; $file = 'user_data/'.$userid.'/'.$month.'/'.$timestamp.".xml"; $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $xml); fclose($fh); }; Thanks for your input! -Adam Quote Link to comment Share on other sites More sharing options...
FaT3oYCG Posted April 10, 2009 Share Posted April 10, 2009 what is this for exactly as its bad practice to store information in fles on the server as they can be accesed with a browser and bypass security measures, that is why we have databases. Quote Link to comment Share on other sites More sharing options...
coolbeansdude51 Posted April 10, 2009 Author Share Posted April 10, 2009 They are backups. I know its a bad practice but unfortunately this is the only way right now. Suggestions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.