koolaid Posted October 8, 2007 Share Posted October 8, 2007 ok here's the skinny. I am an Action Script developer so php is very new to me. I am collecting info from a form in flash and posting it (with php) to a .txt file. I just want to name the directory it saves to with one of my flash variables. <?php ///my flash variables $_POST["repsName"] . $_POST["clientsName"]. $_POST["clientsPhone"]. $_POST["clientsUrl"]. $_POST["shortDescroption"]. $_POST["longDescription"]; ///where i started on the directory thing i know this is where i should ///pass my variable i just don't know how. if(!is_dir("./files")) mkdir("./files", 0755); $mode = file_exists('user_input.txt')?'a':'w'; // append if file exists otherwise create it $fp = fopen('user_input.txt',$mode); // open file fwrite($fp,print_r($_POST,true)."\r\n"); // dump the contents of the $_POST array to the file fclose($fp); ?> oh yeah after i create the directory i would like to write to that directory, or write then move to that directory, but one step at a time huh. Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/ Share on other sites More sharing options...
koolaid Posted October 9, 2007 Author Share Posted October 9, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365392 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 assume you wany something like this!.. but will need to know how you want it formatted. <?php ///my flash variables //$_POST["repsName"] . $_POST["clientsName"]. $_POST["clientsPhone"]. $_POST["clientsUrl"]. //$_POST["shortDescroption"]. $_POST["longDescription"]; ///where i started on the directory thing i know this is where i should ///pass my variable i just don't know how. if(!is_dir("./files")) mkdir("./files", 0755); $mode = file_exists('user_input.txt')?'a':'w'; // append if file exists otherwise create it $fp = fopen('user_input.txt',$mode); // open file foreach($_POST as $K => $V) { fwrite($fp,"$K = $V\r\n"); // dump the contents of the $_POST array to the file } fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365395 Share on other sites More sharing options...
ball420 Posted October 9, 2007 Share Posted October 9, 2007 this is a good question but looking at koolaids code and your code i see what you have changed but am not sure why or what you exactly did. can you explain. thanks Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365412 Share on other sites More sharing options...
koolaid Posted October 9, 2007 Author Share Posted October 9, 2007 assume you wany something like this!.. but will need to know how you want it formatted. <?php ///my flash variables //$_POST["repsName"] . $_POST["clientsName"]. $_POST["clientsPhone"]. $_POST["clientsUrl"]. //$_POST["shortDescroption"]. $_POST["longDescription"]; ///where i started on the directory thing i know this is where i should ///pass my variable i just don't know how. if(!is_dir("./files")) mkdir("./files", 0755); $mode = file_exists('user_input.txt')?'a':'w'; // append if file exists otherwise create it $fp = fopen('user_input.txt',$mode); // open file foreach($_POST as $K => $V) { fwrite($fp,"$K = $V\r\n"); // dump the contents of the $_POST array to the file } fclose($fp); ?> I don't really know how php works, but i was thinking the code wopuld look something like this if(!is_dir("./files")) mkdir("./files"+["clientsName"], 0755); Now I KNOW this is not correct, but do you see what i am trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365414 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 the first code posted will not work.. why add a function to code that will fail!! i have corrected the code posted.. the creating of directorys would be passed via a post command (i assume this from your code) $folder = "./files/".$_POST["clientsName"]."/"; if(!is_dir($folder)) mkdir($folder, 0755); Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365422 Share on other sites More sharing options...
koolaid Posted October 9, 2007 Author Share Posted October 9, 2007 Nice that is exactly what i needed. I tried something almost exactly like that last night as i struggled to try to get it to work. I was so close so that is encouraging. I think i am going to like php. Thanks again man. Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365430 Share on other sites More sharing options...
ball420 Posted October 9, 2007 Share Posted October 9, 2007 that one is going into the archives fo sho! Quote Link to comment https://forums.phpfreaks.com/topic/72362-solved-easy-for-php-heads-pass-a-variable-to-name-a-file/#findComment-365434 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.