PHP Variables Not Loading?

  • Heres a basic script I found, of course not flash 8 formatted to look shiny but:

    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.


  • Try placing the onLoad after the Load, have to set that event handler prior to calling the php. Also, and I don't think this matters, but I always use "echo" vs. print - hmmmm wonder if it matters? So echo $x;


    var phpfilepath = "http://freish.freehostia.com/files.php";

    myVars = new LoadVars();

    myVars.onLoad = function() {
    total.text = this.x;
    }

    myVars.load(phpfilepath);


  • That function as it is written will return 1 no matter how many files are in the directory.

    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.


  • phpfilepath = "http://freish.freehostia.com/files.php";
    myVars = new LoadVars();
    myVars.load(phpfilepath);
    myVars.onLoad = function() {
    total.text = this.total;
    };
    $x = "abc";
    print "total=" . $x;

    ?>


  • Using $path = "http://freish.freehostia.com/pics/"; I'm getting an error:

    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


  • You must name the variable you want loaded into flash. Well, can't say it's defenitively a must but I've done it that way and that works.
    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..


  • That function as it is written will return 1 no matter how many files are in the directory.

    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.


  • You'll have to do it manually...look up the readdir and other directory functions on php.net:
    http://www.php.net/manual/en/function.readdir.php

    There are some pretty good scripts in the comments there...


  • Yeah I think the failure is due to not using a direct root path for PHP to use 'opendir()'. I tried it out with my direct path using this function right here:


    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.


  • What problem? The ampersand isn't needed there plus using short tags and enclosing your variable in the string is bad practice.

    I probably should have used single quotes, echo, and escape characters as well but that really wasnt the question.


  • Check it out, http://freehostia.com/ (press member login at the top) - freish 49018981 - usually I go to file manager & www & freish.freehostia.com folders to access the main things. The pics folder has only 2 photos.


  • 999 your code returned 5 items & odis returned 4. Paths are probably wrong, I'll give the password out (its just a test account, doesnt matter) next post so you guys can see how it's set up.

    Info file here: http://freish.freehostia.com/info.php


  • Thanks for the link, I tried some of those but I still get errors.

    (I dont know PHP btw)


  • Works like a charm. Thanks a lot bro, I will remember this forever :lol:.


  • PHP Version 4.4.0...any code for 4.4?


  • Ok man...

    :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


  • 999 your code returned 5 items & odis returned 4. Paths are probably wrong, I'll give the password out (its just a test account, doesnt matter) next post so you guys can see how it's set up.

    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.


  • I'm trying:


    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.


  • yup np

    :thumb:


  • Thanks 999, good solution for loading that. I have a code by Nokrev which is supposed to detect the amount of items in a folder, using:


    $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?


  • Yeah my bad, that didn't work probably because the while statement was not finding any, it needs an if in there with the counter++ outside. Kinda weird, but works for me. I did test it with your path in there and it results in a 0, which is telling me this is not the correct path or this script must be on their server for it to work properly. Please let me know if this works! I have tested it on my computer with my images folder and it works. http://www.obi-graphics.com/countFiles.php



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

    ?>


  • put this in a new PHP doc and upload it to your server:


    // 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.


  • Its a free hosting I found to test this out, it says PHP enabled, but I cant find where it says what php version?


  • Now, scandir is a php 5 function...do you have php5 on your server?

    When I hit that page, http://freish.freehostia.com/files.php , I get a fatal error...


  • This should return a number. If you need to exclude a specific file type you'll have to add it to the loop. This also counts sub-directories as well.... didnt know if you wanted that or not?


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

    ?>


  • This fixed the problem:
    $x = "abc";
    print "&total=$x";
    ?>


  • i too am having the same issue as you. i cant get flash to load php file.

    let me know if you get it to work.=)







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about PHP Variables Not Loading? , Please add it free.