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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.