Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-17-2008, 08:08 AM   #1
vangojames
Member
 
Join Date: Jul 2008
Posts: 57
Question PHP/Flash problem

Hi, I can't seem to get my flash site to communicate with one of the private folders on the web server it is hosted on. I am trying to use PHP to fetch an XML file from the folder and make it available to flash. I have scripting enabled on the server and I have verified the scripting path to use. The page loads all content but says it is still waiting to access the server when trying to load in the XML file.
The AS3 code is:


ActionScript Code:
package com.net.php {     import flash.events.*;     import flash.net.*;         public class PHPExtLoader extends EventDispatcher     {         public var phpFile:String;         public var remoteFile:String;         public var req:URLRequest;         private var vars:URLVariables = new URLVariables();         private var loader:URLLoader = new URLLoader();         public var data:String;                 public function PHPExtLoader()         {                     }                 public function load(php:String, remote:String):void         {             phpFile = php;             remoteFile = remote;             req = new URLRequest(phpFile);             vars.fileName = remoteFile;             req.data = vars;             req.method = URLRequestMethod.POST;             loader.addEventListener(Event.COMPLETE, contentLoaded);             loader.load(req);         }                 private function contentLoaded(event:Event):void         {             data = loader.data;             dispatchEvent(new Event(Event.COMPLETE));         }             } }

The PHP code is:


PHP Code:
<?php
    $file 
$_POST['fileName'];
    echo 
file_get_contents($file);

?>
I don't know if it is a problem but the calling swf has been loaded by another using the following class to make sure that the parent swf can access the child swf methods:


ActionScript Code:
/* ::DESCRIPTION:: This will load in a SWF and allow it to be accessed through the getPage method in a state where its functions can be accessed by an external caller. It can be unloaded via the unloadPage method. The _currentProgress variable wil return the current percentage of bytes loaded. */ package net {     import flash.events.*;     import flash.display.*;     import flash.net.*;         public class PageLoader extends Loader     {     //::::::::::::VARS:::::::::::         //*********************CONNECTION/LOADING VARS**********************         public var _page:DisplayObject;     public var _currentProgress:Number = 0;         private var _pageURL:String;     private var _pageLoader:Loader;     private var _loaderInfo:LoaderInfo; //::::::::::::PROGRAM:::::::::::         public function PageLoader(PAGESWF:String)         {                _pageURL = PAGESWF;             _pageLoader = new Loader();         }                 public function loadPage():void         {             _pageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, setProg);             _pageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, pageLoaded);             _pageLoader.load(new URLRequest(_pageURL));         }                 private function pageLoaded(event:Event):void         {             _pageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, pageLoaded);             _loaderInfo = event.target as LoaderInfo;             this.dispatchEvent(new Event(Event.COMPLETE));         }                 private function setProg(event:ProgressEvent):void         {             _currentProgress = (event.bytesLoaded / event.bytesTotal);                         if(event.bytesLoaded == event.bytesTotal)             {                 _pageLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, setProg);             }         }         public function getPage():*         {             return _loaderInfo;         }                 public function pageUnload():void         {             _pageLoader.unload();         }     } }


Any help would be really appreciated!! Thanks,

James
vangojames is offline   Reply With Quote
Old 07-18-2008, 01:37 PM   #2
ariel_Ro
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 16
Send a message via Yahoo to ariel_Ro
Default

Try chmod("/somedir/somePhpFile", 0777); it worked for a project I did
ariel_Ro is offline   Reply With Quote
Old 07-18-2008, 02:05 PM   #3
vangojames
Member
 
Join Date: Jul 2008
Posts: 57
Question

Quote:
Originally Posted by ariel_Ro View Post
Try chmod("/somedir/somePhpFile", 0777); it worked for a project I did

Thanks ariel_Ro. I'm pretty new to using PHP and flash, so my PHP knowledge is pretty slim. What does the chmod command do, and how do you use it?

Thanks
vangojames is offline   Reply With Quote
Old 07-18-2008, 02:18 PM   #4
ariel_Ro
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 16
Send a message via Yahoo to ariel_Ro
Default

The idea is that the file on the server you want to access has some permissions. By default, you can't call the script if the server doesn't let you to do so. Chmod stands for "Change mod" so you can enable some of the permissions
PHP Code:
// Everything for owner, read and execute for others
chmod("/somedir/somefile"0755); 
I stole my example from www.php.net/chmod. You can take a peak too
ariel_Ro is offline   Reply With Quote
Old 07-18-2008, 02:41 PM   #5
vangojames
Member
 
Join Date: Jul 2008
Posts: 57
Question

Hmmm can't seem to get it to work still. The file now reads:

PHP Code:
<?php
    $file 
$_POST['fileName'];
  
chmod("$file"0755); 
    echo 
file_get_contents($file);
?>
Is this right? The way I understand it is that the URL that is passed in to the PHP from flash should get it's properties changed by PHP to "Everything for owner, read and execute for others". When my page loads though, it can't sem to load this file in I'm really stuck :-(
vangojames is offline   Reply With Quote
Old 07-18-2008, 03:03 PM   #6
ariel_Ro
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 16
Send a message via Yahoo to ariel_Ro
Default

Not sure if you're doing what you should. To check if the variables arrived well try to write them in a file this way:
PHP Code:
echo "vars=ok";
    
$handle fopen("test.txt""w+");
    
$file $_POST['fileName'];
        
chmod("$file"0755); 
    
fwrite($handlefile_get_contents($file););
    
fclose($handle); 

Last edited by ariel_Ro; 07-18-2008 at 03:13 PM.
ariel_Ro is offline   Reply With Quote
Old 07-19-2008, 11:58 AM   #7
vangojames
Member
 
Join Date: Jul 2008
Posts: 57
Default

It's strange, I can get it working on my WAMP testing server, but when uploaded to the site it doesn't work. On the WAMP testing server I am using the original PHP code, along with the ftp URL. Would this imply that the site is not allowing scripts to run? I have set it to allow scripts to run, and I have verified this with the hosting service. Any ideas?
vangojames is offline   Reply With Quote
Old 07-30-2008, 01:53 PM   #8
QuantumTiger
Member
 
QuantumTiger's Avatar
 
Join Date: Jul 2008
Location: London
Posts: 69
Default

The process running PHP on the server may not have the priviliges to chmod a file in a protected folder. If it did your script would have just opened a massive security hole in your site because any browser could call the php script with ANY file name and if the file exists it would merrily change the security and serve the file. Really NOT recomended!!!

If you want to test if PHP scripts are enabled on the server just do a "hello world" script and see if that runs.
__________________
QT
Shadowfax on ActionScipt
QuantumTiger is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with component scope / calling function FarFeTTu Components 2 03-10-2011 10:19 PM
maybe a caching problem? kath421 ActionScript 2.0 4 03-21-2006 05:41 AM
Problem with loading unloading clips and dynamic text sah302 ActionScript 1.0 (and below) 1 01-06-2006 05:19 PM
HEEELP!!! cant work out the answer to a problem case ActionScript 1.0 (and below) 1 07-29-2003 11:37 PM
global TextField Problem! Guru wonted mediaholic ActionScript 1.0 (and below) 3 07-20-2003 10:07 AM


All times are GMT. The time now is 03:57 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.