A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: pasing date/time stamp to PHP for filename

Threaded View

  1. #1
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755

    pasing date/time stamp to PHP for filename

    ok.. I have my code working.. basically the user drags some clips around the stage (building a chopper)..and hits the "save" button..this will export all the needed properties (_x, _y, _xscale, _yscale..etc..etc) to a textfile as a string (example: &tankData=val1, val2, val3..etc) which i will import and split into an array...so far so good (although i havent tested the loading part yet..should be fine)...as of now I have my PHP script dumping these values to a hardcoded textFile name. (build1.txt)..what i want to do is...instead of using the SAME text file for each save.. I want each save to have its OWN text file. So to be unique I am using a date/tie stamp fucntion I wrote to make a unique fileName that wont be overwritten.

    what I need help on..is ow to pass this function the PHP script?

    here all my code...

    on my SVAE BUTTON: (I call the saveBuild function I wrote)

    button:
    Code:
    on (release) {
    	// [0]=x [1]=y [2]=xscale [3]=yscale [4]=_currentframe [5]=_rotation [6]=partName
    	var frameData = [_root.mainContainer.frameContainer.frame_mc._x, _root.mainContainer.frameContainer.frame_mc._y, _root.mainContainer.frameContainer.frame_mc._xscale, _root.mainContainer.frameContainer.frame_mc._yscale, _root.mainContainer.frameContainer.frame_mc._currentframe, _root.mainContainer.frameContainer.frame_mc._rotation, _root.frameChoice];
    	var tankData = [_root.mainContainer.tankContainer.tank_mc._x, _root.mainContainer.tankContainer.tank_mc._y, _root.mainContainer.tankContainer.tank_mc._xscale, _root.mainContainer.tankContainer.tank_mc._yscale, _root.mainContainer.tankContainer.tank_mc._currentframe, _root.mainContainer.tankContainer.tank_mc._rotation, _root.tankChoice];
    	saveBuild();
    	
    }
    the function it calls is THIS:

    saveBuild function:
    Code:
    function saveBuild() {
    	
    	// call the PHP script & return if save was sucessful.
    	//myTargetPath = "http://www.dmstudios.net/DBB/";
    	
    	// Format variables for PHP
    	sendBuild = new LoadVars();
    	sendBuild.frameData = "&frameData="+frameData;
    	sendBuild.tankData = "&tankData="+tankData;
    	reply = new LoadVars();
    	reply.onLoad = function(success) {
    		if (success) {
    			//error is a variable echo'd in the PHP file.
    			response_txt.text = reply.error; 
    			//check text field to see if the values wrote correctly. (only for testing wont go live)
    			_root.getURL("http://www.dmstudios.net/DBB/build1.txt?" add random(9999), "_blank");
    		}
    	};
    	sendBuild.sendAndLoad("writeTextFile2.php", reply, POST);	
    }
    and here is the PHP script I am using:

    PHP code:
    PHP Code:
    <?
    $myFileName="build1.txt";  // note that either the "files" folder needs chmod 777 or test.dat needs chmod 666 to save anything on unix server
    // note further that accepting an unchecked filename from the web is an invitation to hackers      
    $frameData=$_POST["frameData"];
    $tankData=$_POST["tankData"];
    $fp = fopen ("$myFileName", "w");
    if($fp)
    {  fwrite($fp,stripslashes("$frameData\n$tankData"));  // it does not make sense to write if the fopen failed, so this goes within the if
       fclose($fp);
       echo ("&error=NONE&msg=Save was successful!");
    } else {
    echo ("&error=OK&msg=Save unsuccessful!...an error occurred!");
    }

    ?>

    I have everything woring as it should and how I want it to be.. EXCEPT if you look I am using the SAME textFile hardcoded into the PHP script.

    what i want to do is us the OUTPUT form this function I wrote:

    timeStamp function:
    Code:
    function timeStamp() {
    	//Get DATE:
    myDate = new Date();
    currentDate = myDate.getDate();
    currentMonth =["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
    //currentYear = myDate.getYear(); // last digits of YEAR: 06
    currentYear = myDate.getFullYear();  //fulle YEAR: 2006
    currentHour = myDate.getHours();
    currentMinute = myDate.getMinutes();
    currentSecond = myDate.getSeconds();
    timeStamp = currentMonth[myDate.getMonth()]+currentDate+currentYear+currentHour+currentMinute+currentSecond;
    trace(timeStamp);
    }
    to be the NAME of the text file the PHP script writes to.

    How would I go abotu doing this? (I know 0% php really)

    so wold I just call this function form the button (at the same time I call the saveBuild unction) and then try to pass the result in the varObject I am passing to the PHP script as well??

    or is there a better method? or better practice?

    thanks


    update: I have tried:
    Code:
    var newFileName = timeStamp();
    trace(newFileName);
    but it returns "undefined". I know I am not using it properly to return the results from the function.. HELP???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center