Jump to content

[SOLVED] easy ? for php heads, pass a variable to name a file


koolaid

Recommended Posts

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.

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);
?>

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?

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);

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.