PHP Variables Not Loading?
Posted on March 12th, 2010 by wktd
phpfilepath = "http://freish.freehostia.com/files.php";
myVars = new LoadVars();
myVars.load(phpfilepath);
myVars.onLoad = function() {
total.text = this.x;
};In the php file:
$x = "abc";
print $x;
?>Any reason why flash doesnt load "abc" into total.text? My php file permissions are set to 755 by default.
var phpfilepath = "http://freish.freehostia.com/files.php";
myVars = new LoadVars();
myVars.onLoad = function() {
total.text = this.x;
}
myVars.load(phpfilepath);
Mines working fine for me on my web host and my localhost using absolute or relative links with php 4 nand 5. The error makes it seem like your host doesnt support the function.
Check your phpinfo again to see what functions are allowed.
myVars = new LoadVars();
myVars.load(phpfilepath);
myVars.onLoad = function() {
total.text = this.total;
};
$x = "abc";
print "total=" . $x;
?>
Warning: opendir(http://freish.freehostia.com/pics/): failed to open dir: not implemented in /home/www/freish.freehostia.com/files.php on line 5
message=Error Opening Directory
Also you can load multiple variables or arrays that way
Ex.
$variable1 = "abc";
$variable2 = "def";
$variable3 = "123";
echo "variable1=".$variable1."&variable2=".$variable2."&variable3=".$variable3;
phpfilepath = "http://freish.freehostia.com/files.php";
myVars = new LoadVars();
myVars.load(phpfilepath);
myVars.onLoad = function() {
total1.text = this.variable1;
total2.text = this.variable2;
total3.text = this.variable3;
};
//Edit: didn't notice that 999 had posted the solution before i replied... oh well..
Mines working fine for me on my web host and my localhost using absolute or relative links with php 4 nand 5. The error makes it seem like your host doesnt support the function.
Check your phpinfo again to see what functions are allowed.
Yes in regards to what 999 has said about the phpinfo(), please send a link to that so we can take a look if nothing works.
http://www.php.net/manual/en/function.readdir.php
There are some pretty good scripts in the comments there...
function countfiles($path) {
$dir = opendir($path) or die("Error Opening Directory");
while ($file = readdir($dir) && $file != "." && $file != ".."){
$i++;
}//end while
closedir($dir);
return $i;
}
$num_files = countfiles("/home/users/web/****/*****/htdocs/images/");
echo $num_files;
?>
So if you can find that direct root path for that site, then it should work.
I probably should have used single quotes, echo, and escape characters as well but that really wasnt the question.
Info file here: http://freish.freehostia.com/info.php
(I dont know PHP btw)
:smirk: I think I gots it working for ya!
$dir = ("/home/www/freish.freehostia.com/pics");
$handle = opendir($dir) or die("Couldnt open");
$count = 0;
$array = array();
while (false !== ($file = readdir($handle))) {
if ($file !== '.' && $file !== '..')
{
$array[$count] = $file;
$count++;
}
}
echo $count . "
";
foreach ($array as $file){
echo "file name: " . $file . "
";
}
?>
Here is your link to it, and feel free to alter that file in your directory!
http://freish.freehostia.com/testCount2.php
--Raymond
Info file here: http://freish.freehostia.com/info.php
Thats odd, /home/www/freish.freehostia.com is your document root, so that last code should work.
function countfiles($path) {
$dir = opendir($path) or die("Error Opening Directory");
while ($file = readdir($dir) && $file != "." && $file != ".."){
$i++;
}//end while
closedir($dir);
return $i;
}
$num_files = countfiles("/home/www/freish.freehostia.com/pics/");
echo $num_files;
?>It returns 1, there are two files in that folder though.
:thumb:
$dir = 'http://freish.freehostia.com/pics/';
$files = scandir($dir);
$fileamount = count($files)-2;
print "total=" . $fileamount;
?>Basically I'm looking for a code to return the value of the amount of items inside a given directory & I need flash to load that value, but flash loads undefined at the moment. Any ideas?
$dir = ("/home/www/freish.freehostia.com/pics");
$handle = opendir($dir);
$count = 0;
while (false !== ($file = readdir($handle))) {
if (is_file($file) && $file !== '.' && $file !== '..')
{
}
$count++;
}
echo $count;
?>
// Show all information, defaults to INFO_ALL
phpinfo();
?>
then hit it with your browser. It will give you all sorts of environment variables about what's installed.
When I hit that page, http://freish.freehostia.com/files.php , I get a fatal error...
$path = "your_path";
$dir_handle = opendir($path) or die("message=Error Opening Directory");
while ($file = readdir($dir_handle)) {
if ($file != '.' and $file != '..' and $file != 'Thumbs.db') $files=$file;
}
$num = count($files);
echo $num;
closedir($dir_handle);
?>
$x = "abc";
print "&total=$x";
?>
let me know if you get it to work.=)
#If you have any other info about this subject , Please add it free.# |