A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: PHP script works when targetted directly...not through Flash?

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

    PHP script works when targetted directly...not through Flash?

    I have a php script I cobbled together..

    and when I target it directly in my browser (running through WAMP server)

    it seems to do fine..

    recursively searches through ALL text files in a given directory....

    search line by line for a string match.. when found..it dumps that WHOLE line to an array (moves onto next file until done)..

    when done.. I loop through this array.. dumping the contents to a .text file.

    again..everything works fine.. (even if the php is messy..as I dont know much/any php)


    the problem seems to happen when I try to pass in the 3 hard coded vars for the script from a Flash interface...

    just doesnt seem to work..

    I am using a sendAndLoad method from a LoadVars() object..

    to pass in the 3 vars to the php script.. how I check to see if the php script is receiving them? (usually I would use echo or print..but I am sending the data from a flash movie..and not using getURL() or anything or lading a new browser..

    just tryign to send it some data to be used in a few php functions.. and create a text file..


    (my last step is I want to send a trigger/flag/message form php when the txt file has been created....but I cant even pass the data from flash for some reason?)

    the problem is the first 3 vars in the script.. hardcoded..it works as it should..

    when trying to pass those vars form FLASH (POST) using a sendAndLoad..no go.


    PHP Code:
    <?php
    //multi file, recursive text doc search
    $searchTerm "000103309849";
    $targetYear "2011";
    $targetMonth "January";
    $reportName "itemized_report.txt";


    //$targetYear = $_POST["targetYear"];
    //$targetMonth = $_POST["targetMonth"];
    //$searchTerm = $_POST['searchTerm'];
    //$reportName = $_POST["reportName"];

    //array of all files in directory needing to be searched
    $fileArray = array(); 
    //cummulative total of all files needing to be searched (ie: $fileArray array length)
    $totalFiles 0;
    //array of all records found during the file(s) search
    $recordArray = array();
    //cummulative total of all records returned during search (ie: $recordArray array length)
    $totalRecords 0;
    //counter for current file being searched
    $currentFile 0;
    //counter for the current record found in current file
    $tempCount 0;


    //-------------------------------------------------------------------------------//

    function exportData(){
        global 
    $fileArray;
        global 
    $totalFiles;
        global 
    $recordArray;
        global 
    $totalRecords;
        global 
    $reportName;
        
    //echo("CREATING ITEMIZED REPORT<br /><br />");
        
        
    $myFile $reportName;
        
    $fh fopen($myFile'w') or die("can't open file");

        
    $headerData "Transaction Type^HAR ID#^Procedure Code^Description^Transaction Date^Payor^Transaction Amount";
        
    //echo($headerData . "<br>");
        
    fwrite($fh$headerData "\r\n");

        foreach (
    $recordArray as $value){
              
    //echo($value . "<br>");
            
    fwrite($fh$value);
        }
        
    fclose($fh);
    }

    function 
    searchContents(){
        global 
    $searchTerm;
        global 
    $fileArray;
        global 
    $totalFiles;
        global 
    $totalRecords;
        global 
    $currentFile;
        global 
    $recordArray;
        global 
    $tempCount;
        global 
    $targetYear;
        global 
    $targetMonth;
        
    //print_r("<br>second function called <BR><BR>");

        
    $fp fopen($targetYear "/" $targetMonth "/" $fileArray[$currentFile],'rb');
        
    //$fp = fopen($fileArray[$currentFile],'rb');
        //print_r("TARGET FILE : " . $fileArray[$currentFile] . "<BR><BR>");

        
    $tempCount 0;
        while(!
    feof($fp)) {
              
    $newLine fgets($fp);
              if(
    $newLine === false) {
                break;
            }else{
                  
    // ... do something with $newLine
                //print_r("NEW LINE: " . $newLine . "<br>");
                //search $newLine string for search word
                
    if (strpos($newLine,$searchTerm)) { 
                    
    //echo ("MATCH FOUND: "); 
                    
    array_push($recordArray$newLine);
                    
    //print_r($newLine . "<br>");
                    
    $totalRecords++;
                    
    $tempCount++;
                }else{
                    
    //do nothing
                
    }
            }
        }
        
    $currentFile++;
        
    //print_r("<br> CURRENT FILE: " . $currentFile);
        //print_r("FOUND IN CURRENT FILE: " . $tempCount);
        //print_r("<br><br> TOTAL FOUND IN SEARCH: " . $totalRecords);
        //print_r("<br>CUMMULATIVE TOTAL: " . count($recordArray) . "<br><br>");
        //close file
        
    fclose($fp);
        
        if(
    $currentFile $totalFiles){
            
    searchContents();
        }else{
            
    //do nothing..last file searched
            
    print_r("<br> DONE SEARCHING ALL FILES!");
            
    print_r("<br> FINAL TOTAL (Array Count): " count($recordArray) . "<br><br>");
            
    //print_r($recordArray);
            
    exportData();
        }    
    }

    function 
    getFileNames(){    
        global 
    $fileArray;
        global 
    $totalRecords;
        global 
    $totalFiles;
        global 
    $reportName;
        global 
    $targetYear;
        global 
    $targetMonth;
        
        if (
    $handle opendir($targetYear "/" $targetMonth)) {
        
    //if ($handle = opendir('.')) {
            
    while (false !== ($file readdir($handle))) {
                if(
    $file !='getFileNames.php'  && $file != 'AC_RunActiveContent.js' && $file != 'itemizedApplication.swf' && $file != 'itemizedApplication.fla'  && $file != 'itemizedApplication.html' && $file != $reportName &&  $file !='fileSearch-2.php' && $file !='.' && $file !='..'){
                    
    array_push($fileArray,$file);                
                    
    $totalFiles count($fileArray);
                }
            }   
            
    closedir($handle);

        
    //check array contents
        //print_r($fileArray);
        //print_r("<br><br>Total FILES TO SEARCH: " . $totalFiles ."<br><br>");
        
    }
        
    //call next function to search file contents
        
    searchContents();

        
    //test function
        //arrayCheck();
        
    }
    getFileNames();

    ?>

    what am I missing or doing wrong?

    thanks






    update:
    28+ views in a few hours?..no body has a guess? suggest anything.. I just piece-meal'd this together. so any advice is helpful.

    thanks =)

  2. #2
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    I've never had any luck calling php directly from flash, but I've had GREAT success using amfphp and it's easy to set up, test a script, call it from AS and get the returns.

    http://amfphp.sourceforge.net/

    If you end up looking into doing that and have any questions, let me know.

    Hope that helps!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  3. #3
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,320
    When using sendAndLoad you can listen for the onload. Usually this would be the echo from the php script.

    Can you show your sendAndLoad Code?
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    hi guys.. (thanks for the reply)

    first..I fixed it.

    I was didnt realize that when I was using WAMP server (local sever)..

    my call to the .php script (relative path: /sript.php) doesnt work when being tested through the IDE.. (to do that.. I need to actually test through the .html page.)

    I just needed to use my absolute path (momentarily) to my WAMP www directory where my projects resides.

    (DOH!).. I think being very low on my php skills..I wasnt 'punk'd' and not thinking clearly haha..



    @fp1-

    I have never used amfphp, but have read about it many times..(I'll check it out)..thanks for the offer. =)


    @wd-

    I did define my return object for the sendAndLoad() method.. (thanks)..

    and I am getting my return data when things are done.

    thanks guys!

    oh..as far as php syntax..is that how you are 'supposed' to do it? 're-define' the variable with global in front of it in any/every function block that needs to access/alter it?

    thanks

  5. #5
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Whispers,

    I just read your post. I am having a similar kind of problem.

    PHP directly - Works!
    PHP from Flash SWF - Works!
    PHP from Flex SWF - Not Working!

    I tried a few options regarding abso/relative paths but that too does not makes PHP work! Request you to please help me with your posibilities and debugging tricks?

    Paul and FlashPipe1...great if you guys would also share a thought!

    Thanks in advance for your kind consideration! I am just stuck...dun no where to start from
    As ever,
    Vinayak Kadam

  6. #6
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,930
    I haven't done much flex development and none with php calls, but I do know that amfphp does work within flex and I've had great success with it from flash. Not sure how far down the development road you are, but, if you haven't "committed" to the straight php route yet, amfphp is an easy way to call a php function directly and get a return.

    Hope that helps!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  7. #7

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    @vinayak:

    have you checked your sandbox settings (allow network vs. allow local file access)?

    Musicman

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