Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting to Text Files 1

Status
Not open for further replies.

chant9

Technical User
Aug 30, 2005
7
Hi

I want to be able to export some data to a text file from Flash. Preferable into csv format but any text will do. I hoped this would be quite simple but I cant find much on it.

Has anyone tried this or got any advice in doing it.

Thanks
 
You would have to use a server side script to accopmlish this.

Wow JT that almost looked like you knew what you were doing!
 
I too am looking for a way to do this.
right now i have an email script that sends all the provided info from the form in Flash, but i would like to modify the script to append all the data to a "*.csv".

i have found this on another forum, but i have not been able to successfully piece them together
<code>
<?php
$content = "Name:".$_POST["name"]." Address:".$_POST["address"];
$fp = fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
?>
</code>

Any help would be severely appreciated.

Thanks
 
trouble with above code is that any values in the csv file will be overwritten each time you add data

create a notepad file myText.csv and use this php cade

<?php
$Address = $_POST["address"];
$Name = $_POST["name"];
$name = stripslashes($Name);
$address = stripslashes($Address);
$filename = "myText.csv";
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
$Input = ",".$address.",".$name;
$New = "$Input$OldData";
$fp = fopen( $filename,"w");
fwrite($fp, $New, 800000);
fclose( $fp );
?>

all data in the file will now be comma separarted
 
Ok here we are this issue has raised other issues.
im writting to the text file fine.

i ran into issues with people entering commas and carrige returns in the fields that were throwing of the cols in the csv. thats fixed now but NOW there is more.

We decided to have it make a new row for each zip code that is entered. everything works fine except if they only enter one zip code in the first field it writes nothing.

if they enter a zip code in more than just the first field it writes a row for each one fine except it skips the first the row all together.


Code:
<?php
// name of file you will be writing to this file must have read write access set to it, mine did by default but just watch out for this
$file = "data.csv";

$first_name = $_POST[ 'first_name' ];
$last_name = $_POST[ 'last_name' ];
$email = $_POST[ 'email' ];
$address = $_POST[ 'address' ];
$city = $_POST[ 'city' ];
$state_in = $_POST[ 'state_in' ];
$zip_code = $_POST[ 'zip_code' ];
$phone = $_POST[ 'phone' ];
$fax = $_POST[ 'fax' ];
$state_interest = $_POST[ 'state_interest' ];

$zipone = $_POST[ 'zipone' ];
$zip2 = $_POST[ 'zip2' ];
$zip3 = $_POST[ 'zip3' ];
$zip4 = $_POST[ 'zip4' ];
$zip5 = $_POST[ 'zip5' ];
$zip6 = $_POST[ 'zip6' ];
$zip7 = $_POST[ 'zip7' ];
$zip8 = $_POST[ 'zip8' ];
$zip9 = $_POST[ 'zip9' ];
$zip10 = $_POST[ 'zip10' ];

$occupation = $_POST[ 'occupation' ];
$experience = $_POST[ 'experience' ];
$net_worth = $_POST[ 'net_worth' ];
$liquid = $_POST[ 'liquid' ];
$interest = $_POST[ 'interest' ];
$comments = $_POST[ 'comments' ];

$search = array( ",", "\r" );
$replace = array( " ", " " );

$first_name = str_replace( $search, $replace, $first_name );
$last_name = str_replace( $search, $replace, $last_name );
$email = str_replace( $search, $replace, $email );
$address = str_replace( $search, $replace, $address );
$city = str_replace( $search, $replace, $city );
$state_in = str_replace( $search, $replace, $state_in );
$zip_code = str_replace( $search, $replace, $zip_code );
$phone = str_replace( $search, $replace, $phone );
$fax = str_replace( $search, $replace, $fax );
$state_interest = str_replace( $search, $replace, $state_interest );

$zipone = str_replace( $search, $replace, $zipone );
$zip2 = str_replace( $search, $replace, $zip2 );
$zip3 = str_replace( $search, $replace, $zip3 );
$zip4 = str_replace( $search, $replace, $zip4 );
$zip5 = str_replace( $search, $replace, $zip5 );
$zip6 = str_replace( $search, $replace, $zip6 );
$zip7 = str_replace( $search, $replace, $zip7 );
$zip8 = str_replace( $search, $replace, $zip8 );
$zip9 = str_replace( $search, $replace, $zip9 );
$zip10 = str_replace( $search, $replace, $zip10 );

$occupation = str_replace( $search, $replace, $occupation );
$experience = str_replace( $search, $replace, $experience );
$net_worth = str_replace( $search, $replace, $net_worth );
$liquid = str_replace( $search, $replace, $liquid );
$interest = str_replace( $search, $replace, $interest );
$comments = str_replace( $search, $replace, $comments );

$zip = array( $zipone, $zip2, $zip3, $zip4, $zip5, $zip6, $zip7, $zip8, $zip9, $zip10 );

// opens the file you will write to, uses the variable $file to point to it
// the 'a' means that it should append the information to what already exists
$fp = fopen( $file, 'aw' );

$i = 1;
while( strcmp( $zip[$i], "" ) != 0 && $i <= 10 )
{
	// combine variables into the csv format add or delete variable depending on what fields or data you need.
    // the slash "\n" adds a line break
    $data = $first_name ."," . $last_name . "," . $email . "," . $address . "," . $city . "," . $state_in . "," . $zip_code . "," . $phone . "," . $fax . ",";
    $data .= $state_interest ."," . $zip[$i] ."," . $occupation ."," . $experience ."," . $net_worth . "," . $liquid ."," . $interest_level ."," . $comments ."\n";
    
    fwrite( $fp, $data );
    	
    $i++;
}

fclose( $fp );


$responseFromName = "";
$responseFromEmail = "";
$subject = "";

//enter body for the auto response
$body = "";

mail( $email, $subject, $body, "From: $responseFromName\r\nReply-to: $responseFromEmail\r\n");
?>

Any Thoughts on this Maddness because im at a loss
 
looks like you are starting the array at 1

first element of the array is 0

$i = 0;
while( strcmp( $zip[$i], "" ) $i < 10 )
{

try that
 
Code:
$i = 0;
while( strcmp( $zip[$i], "" ) != 0 && $i <= 10 )
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
oops I mean that one.
changed $i = 1; --to--> $i = 0;

Thanks Bill!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top