Accessing $_POST from a controller

Hello,

I am trying to adapt this tiny script that loads SWF files from the server to a Yii-based website so I could add it some RBAC.


header('Pragma: no-cache');

header('Cache-Control: no-cache, must-revalidate');

header('Content-type: application/x-shockwave-flash');


if ($_POST['file'])

{

	$url = $_POST['file'] .'.swf';

	if (file_exists($url))

	{

		$res = fopen($url, 'r');

		$data = fread($res, filesize($url));

		echo $data;

		fclose($res);

	}

}

So I created a Flash controller with this code:


	public function actionFile()

	{	

		if ($_POST['file'])

		{

			$url = 'protected/flash/'. $_POST['file'] .'.swf';

			if (file_exists($url))

			{

				$res = fopen($url, 'r');

				$data = fread($res, filesize($url));

				echo $data;

				fclose($res);

			}

		}

	}

But I get this error message, highlighting the “if ($_POST[‘file’])” line:

Also, I would like to know if it is possible to access a controller through a POST request, considering my flash file would call this website with this method?

Thanks.

well,

I’m not a FLASH guy, but you can do a:




var_dump( $_POST ); // in the controller's action



and check your POST variables, maybe that’ll help a little

–iM

I already did it but it is not helpful because my problem is not to know what variables are in $_POST, but simply to access their values, because Yii seems to have a problem when I simply use “$_POST[‘file’]”…

I must do something wrong but I do not see what.

Would be?

<form [color="#FF0000"]enctype="multipart/form-data"[/color] action="" method="post">

or you can try this one too (it should return $_GET and $_POST variables!)




  $file_name = Yii::app()->request->getParam( 'file' );



–iM

could you please show your view file. what is this ‘file’.

is it submit button or something?

I solved the problem using


 if (isset($_POST['file']))

instead of simply


 if ($_POST['file'])

This way when $_POST[‘file’] is undefined, there is no error.