Page 1 of 1

Please Check my Code

Posted: Sat Dec 03, 2005 8:04 am
by Blyant
I'm currently using this piece of PHP to print out an XML document to be used i flash it works very well:

Code: Select all

<?php
echo "<?xml version=\"1.0\" encoding =\"ISO-8859-1\" ?>\n";
echo "<images>\n";
if ($handle = opendir('./portfolio')) {
	$files_array = array();
	// Gather files in array
	while (false !== ($file = readdir($handle))) {
		if ($file !== "." && $file !== "..") {
			list($width, $height) = getimagesize("portfolio/".$file);
			$mtime = filemtime("portfolio/" . "$file");
			array_push($files_array, array(
				'mtime' => $mtime,
				'path' =>  "portfolio/" . "$file",
				'width' => $width,
				'height' => $height
			));
		}
	}
	// Sort array
	rsort($files_array);
	// Print XML
	for ($i=0;$i<count($files_array);$i++) {
		echo "<myImage myPath=\"" . $files_array[$i]['path'] ."\" myWidth=\"" . $files_array[$i]['width'] ."\" myHeight=\"" . $files_array[$i]['height'] ."\" />\n";
	}
	closedir($handle);
}
echo "</images>\n"
?>
However I want to start to post a variable from flash that defines which directory to open (currently defined as "portfolio"). I'm trying the code below to define the directory as a variable without success, I'm not sure if the problem is here in the PHP or in my Actionscript. If there are problems here could somene be kind enough to point them out to me:

Code: Select all

....
$myFileName = $_POST["myFileName"];
if ($handle = opendir('./$myFileName'))
.....

Posted: Sat Dec 03, 2005 8:13 am
by sheila
You need double quotes when you use $myFileName

Code: Select all

$myFileName = $_POST["myFileName"];
if ($handle = opendir("./$myFileName"))

Posted: Sat Dec 03, 2005 8:20 am
by neophyte
I'd make sure first the variables are arriving in $_POST.

Code: Select all

vardump($_POST);
I didn't know you could use XML to import variables into Flash. I've only used the sendAndRecieve object and query strings.

Good luck.

Posted: Sat Dec 03, 2005 8:36 am
by Blyant
Thanks for the pointers, it seems as though the problem is in my actionscript. I see the problem now, but is above my actionscript ability. I'll have to get over to the Macromeida forum and hope someone takes pitty on me.
I didn't know you could use XML to import variables into Flash. I've only used the sendAndRecieve object and query strings.
Apparently Flash loves a bit of XML.