dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Error opening URL - Flash -> PHP -> Flash

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    6

    Error opening URL - Flash -> PHP -> Flash

    Hello,

    I'm new to these forums but have spent quite a bit of time at Flashkit and I still cannot figure out why I'm having the problem I am.

    Basically, at the moment, all I'm trying to do is send a file name and extention to a php script, which will then load the file and return the contents of the file (a text file, btw) back to flash.

    I'm trying to test this from within the flash environment and my PHP is setup on my web host server.

    When I test the Flash out, I get the following trace error:

    "Error opening URL 'http://www.obsidiangateway.net/phpOperations/op_loadhtml.php'"

    (which is the address of the test php script.)

    My flash code is:
    var myData:LoadVars = new LoadVars();
    myData.file = "test";
    myData.ext = "html";
    myData.onLoad = function(){
    _global.html_content = this.html_content;
    }
    myData.sendAndLoad("http://www.obsidiangateway.net/phpOperations/op_loadhtml.php",myData);


    My php script is:
    PHP Code:
    <?php
    if (empty($file)){
        print (
    "html_content=NO FILE DEFINED");
    }
    else{
        
    $lines file("$file.$ext");
        
    $HTML_Content "";
        foreach (
    $lines as $value){
            
    $HTML_Content .= $value;
        }
        print (
    "html_content=$HTML_Content");
    }
    ?>
    The PHP works perfectly if I access it directly from the browser, but fails when trying to access it from flash. What am I doing wrong?

    Thank you

  2. #2
    It's a long way to the middle launchpad67's Avatar
    Join Date
    Oct 2004
    Location
    Prescott, Arizona
    Posts
    1,387
    You can't test a php script through flash, on your computer. The only way to see if this works is to upload everything to your server, then try it from there.

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by launchpad67
    You can't test a php script through flash, on your computer. The only way to see if this works is to upload everything to your server, then try it from there.
    *sighs* I expected this was the case. I tried uploading the swf file and it didn't seem to work, but upon closer examination, I found I had set something up wrong. When I upload it works fine, thank you.

    However, is there no way at all I can have a flash file call a php script while the flash file is local and the php is on the internet? I read that flash has security that will not allow it, but that there is a bypass with the inclusion of a "crossdomain.xml" file. I have one in the same directory as my flash file, but it doesn't seem to do anything. Am I grasping at straws? It's a bit cumbersome if I have to keep publishing and uploading the swf file every time I wish to test it or the script. I know I could setup a web server locally, but, let's just say that's not an option I want to consider at this time.

    Anyway, thanks!

  4. #4
    It's a long way to the middle launchpad67's Avatar
    Join Date
    Oct 2004
    Location
    Prescott, Arizona
    Posts
    1,387
    Well, you can install PHP on your computer. Then you can test anything you want. I believe the web address is http://www.php.net/downloads.php

    Note: If you use a good FTP client application, then you can make your workflow much easier. So uploading files after you modify them becomes simple, and then you can get into a rhythm of 'edit', 'save', 'upload', 'view' !

  5. #5
    Junior Member
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by launchpad67
    Well, you can install PHP on your computer. Then you can test anything you want. I believe the web address is http://www.php.net/downloads.php

    Note: If you use a good FTP client application, then you can make your workflow much easier. So uploading files after you modify them becomes simple, and then you can get into a rhythm of 'edit', 'save', 'upload', 'view' !
    Actually, installing php isn't quiet enough, I do not think. PHP doesn't even initially install as a shell scripting language by default. Besides, even if it did, I don't think flash can call those. The php script would have to be called from a webserver, so, at the very least, I would need to install php and apache (or other webserver software). I've done it before on other computers, I just want to try and avoid setting it all up on this machine.

    Truth be told, the whole upload for testing thing isn't that big a deal, so I can live with it. The only thing was this flash project is partly a final project for a class, but if it cannot call the require scripts without being on the server, then the flash would be unviewable to my course professor on the schools computers. Eh... no big thing again.

    Thanks again

  6. #6
    It's a long way to the middle launchpad67's Avatar
    Join Date
    Oct 2004
    Location
    Prescott, Arizona
    Posts
    1,387
    Quote Originally Posted by ObsidianBlk
    The only thing was this flash project is partly a final project for a class, but if it cannot call the require scripts without being on the server, then the flash would be unviewable to my course professor on the schools computers. Eh... no big thing again.
    Well if you can't access the internet as part of your class final, then you should re-think your approach to this project. I run a few servers but I don't have php installed on my computer at home/office. So, like you said, to do the whole upload/ test thing isn't a big deal.
    I really don't see any other way around it. I mean, think about it. Your script is calling an external 'server side script' in order to carry out it's function.
    Good luck. Let me know if I can help in any other way.

  7. #7
    Junior Member
    Join Date
    May 2006
    Posts
    3
    Quote Originally Posted by ObsidianBlk
    but upon closer examination, I found I had set something up wrong. When I upload it works fine, thank you.
    Hello ObsidianBlk,

    Would you please elaborate on what was set up wrong? I am experiencing the same problem (html form connects with the php script fine, but flash has an "Error opening URL" error), even when the swf is on my server.

    Thank You,

    -b

  8. #8
    Junior Member
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by bungalow
    Hello ObsidianBlk,

    Would you please elaborate on what was set up wrong? I am experiencing the same problem (html form connects with the php script fine, but flash has an "Error opening URL" error), even when the swf is on my server.

    Thank You,

    -b
    I think what I meant was that mine worked when I uploaded the swf to my server. How are you sending your information to from Flash to your PHP? And where is your script in relation to your swf? When I tested mine, they were in the same directory.

  9. #9
    Junior Member
    Join Date
    May 2006
    Posts
    3
    Quote Originally Posted by ObsidianBlk
    I think what I meant was that mine worked when I uploaded the swf to my server. How are you sending your information to from Flash to your PHP? And where is your script in relation to your swf? When I tested mine, they were in the same directory.
    Thank you for replying so quickly. I'm using a LoadVars object:

    var dataSender:LoadVars = new LoadVars();
    dataSender.avariable = "Hello World";
    var receiver:Object = new Object();
    receiver.onLoad = function() {
    trace("onLoad called");
    };
    dataSender.sendAndLoad(url, receiver, "POST");

    As I mentioned, this displays an "Error opening URL" message in the trace window when I test from within Flash, and it fails to connect when I place the swf in the same directory on the server as the php script. I have tested setting the url variable to several different URLs on the target server, including non-dynamic html pages, but they all fail.

    However, if I try a URL on a different server to which I have partial access, the transmission is successful, even from within the Flash test environment (the Publish Settings need to have the "Local Playback Security" set to "Access network only"). The problem is that I cannot use that server for full-fledged testing, so I am trying to determine what settings on my test server are causing the problem.

    Thank You,

    -b

  10. #10
    Junior Member
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by bungalow
    Thank you for replying so quickly. I'm using a LoadVars object:

    var dataSender:LoadVars = new LoadVars();
    dataSender.avariable = "Hello World";
    var receiver:Object = new Object();
    receiver.onLoad = function() {
    trace("onLoad called");
    };
    dataSender.sendAndLoad(url, receiver, "POST");

    As I mentioned, this displays an "Error opening URL" message in the trace window when I test from within Flash, and it fails to connect when I place the swf in the same directory on the server as the php script. I have tested setting the url variable to several different URLs on the target server, including non-dynamic html pages, but they all fail.

    However, if I try a URL on a different server to which I have partial access, the transmission is successful, even from within the Flash test environment (the Publish Settings need to have the "Local Playback Security" set to "Access network only"). The problem is that I cannot use that server for full-fledged testing, so I am trying to determine what settings on my test server are causing the problem.

    Thank You,

    -b
    Hmmm... The only thing I can think of at the moment is that in the PHP init file (which is controlled by the server) there is a variable that can be set to allow or deny variables to be sent (I think it's only deniable via POST, but not 100% sure). At the moment, the name of this variable escapes me, I'm sorry, but I do recall a number of threads on this site mentioned it.

    If you have control over the server that is giving you problems, you may want to find that variable and check to see if your servers PHP setting is set for deny. If you do not have control over that server there is very little you can do other than asking the admins to change the variable or for you to go to another server.

    Regardless, however, if you want, you can send me a link to a test swf/php that isn't working for you and I can try it on my server. This was we can be definitly see if it's an actionscript issue or a server one.

  11. #11
    Junior Member
    Join Date
    May 2006
    Posts
    3
    It turns out that there was simply a problem in the PHP script. The "Error opening URL" message threw me for a loop because it didn't appear when connecting to one server but did when connecting to my test server, making me think there was something amiss with the test server. I don't know why that one server lets me test from within Flash, but the other server doesn't, but in any case, my Flash app is now talking to my test server from within a browser.

    Much thanks to ObsidianBlk.

    Kind Regards,

    -b

  12. #12
    Junior Member
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by bungalow
    It turns out that there was simply a problem in the PHP script. The "Error opening URL" message threw me for a loop because it didn't appear when connecting to one server but did when connecting to my test server, making me think there was something amiss with the test server. I don't know why that one server lets me test from within Flash, but the other server doesn't, but in any case, my Flash app is now talking to my test server from within a browser.

    Much thanks to ObsidianBlk.

    Kind Regards,

    -b
    No problem! I wish you luck with your project!

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