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...'); } // ... ?> Link to comment https://forums.phpfreaks.com/topic/233289-help-writing-to-a-file/ 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. Link to comment https://forums.phpfreaks.com/topic/233289-help-writing-to-a-file/#findComment-1199741 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 Link to comment https://forums.phpfreaks.com/topic/233289-help-writing-to-a-file/#findComment-1199751 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...'); } // ... ?> Link to comment https://forums.phpfreaks.com/topic/233289-help-writing-to-a-file/#findComment-1199767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.