Deanznet Posted April 10, 2011 Share Posted April 10, 2011 I need help! I cant get this to write the correct way! What i need is based on the value of what is posted to the script it has to write it in the config file and also make a folder! Please help <?php $start = '$uploadpath=\''; $structure = '../banner/images/'.$_POST['FOLDER'].'\';\n'; $myFile = "PHP/confup.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?\n"; fwrite($fh, $stringData); $stringData = "$start $structure"; fwrite($fh, $stringData); $stringData = "?>\n"; fwrite($fh, $stringData); fclose($fh); // Desired folder structure // To create the nested structure, the $recursive parameter // to mkdir() must be specified. if (!mkdir($structure, 0777, true)) { die('Failed to create folders...'); } // ... ?> Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 10, 2011 Share Posted April 10, 2011 There's a little problem right here: $structure = '../banner/images/'.$_POST['FOLDER'].'\';\n'; Strings in single quotes won't evaluate special characters like \n or \r, etc. So it's literally inserting ../banner/images/';\n into the php file. Also, you're putting the same variable into mkdir(), which won't work.. unless you want a folder named exactly what I said above. Quote Link to comment Share on other sites More sharing options...
Deanznet Posted April 10, 2011 Author Share Posted April 10, 2011 I tried it.. Im having the hardest time doing this What i need the script basicly to do is. Make a folder in ../banner/images/FOLDERPOSTNAME also it has to edit a php file and add $uploadpath='../banner/images/FOLDERPOSTNAME '; Whats the best way Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 10, 2011 Share Posted April 10, 2011 This'll do what you were trying to do: <?php $structure = "../banner/images/".$_POST['FOLDER']; $myFile = "PHP/confup.php"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, "<?php \$uploadpath='$structure'; ?>"); fclose($fh); // Desired folder structure // To create the nested structure, the $recursive parameter // to mkdir() must be specified. if (!mkdir($structure, 0775, true)) { die('Failed to create folders...'); } // ... ?> 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.