[Chameleon] Problem with new widget - adapt php code

Ines mleonsoft at yahoo.com.ar
Mon Mar 26 09:21:54 EST 2007

Hello, I´m tring to create a new widget. It is very simple but I have a
problem doing it.

The function of my new widget is: upload files to the server.

I have proved a php code out of the ms4w, and it works wery well. Now I
added this code to my new widget but the problem is that my application is
reinitiated permanently when I execute the widget.
And I have some doubts about the sintax of the code in the widget.
I send:
1) the php code
2) The code of the template.html and the code of the widget with my doubts.

<form action="subearchivo.php" method="post" enctype="multipart/form-data">
    <b>Enter an XML file: </b>
    <input name="userfile" type="file">
    <input type="submit" value="Submit">
//datos del arhivo
$name_file = $HTTP_POST_FILES['userfile']['name'];
$type_file = $HTTP_POST_FILES['userfile']['type'];
$size_file = $HTTP_POST_FILES['userfile']['size'];
//I verify if the characteristics of the file are those that desire
if (!(strpos($type_file, "xml"))) {
    echo "The extension is not correct. <br><br><table><tr><td><li>It Allows
files .xml
    if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
//I rename the file to upload it to the the server with the name I want
       echo "The upload is success.";
       echo "Error to upload the file.";

In the template.html of muy application I changed this line:
<form method="post">
for this line (like upfile.php):
<form method="post" enctype="multipart/form-data">
And the tag of the widget is:
<cwc2 type="Subexml"
     toolset="nav"> <image state="normal"/> <image state="hover"/> <image

function DrawPublish()
        // init vars
		$szReturn = "<font color='#000000' size='2' face='Arial, Helvetica,
sans-serif'>Enter an XML file: </font><input name='userfile' type='file'> ";

        // execute parent
        $szReturn .= parent::DrawPublish();

        // return
        return $szReturn;

    // end DrawPublish() function

 function  ParseURL()
        // execute parent function
if ( $this->isVarSet( "NAV_CMD" ) &&
                            $this->getVar( "NAV_CMD" ) == 'Subexml' )
	if ( $this->mszCoords == 'bb')
		if ($this->isVarSet('userfile'))
			$this->name_file = $HTTP_POST_FILES['userfile']['name'];
			$this->type_file = $HTTP_POST_FILES['userfile']['type'];
			$this->size_file = $HTTP_POST_FILES['userfile']['size'];
			if (!(strpos($this->type_file, "xml"))) {
			    echo "The extension is not correct. <br><br><table><tr><td><li>It
Allows files .xml
			    if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
			       echo "The upload is success.";
			       echo "Error to upload the file.";

With this code my application ever is looping.
First, I select a file to upload in the server, and the I click the button
of the new widget. And then the application is refreshing, and refreshing
and refreshing.....
a) I'm not sure if is correct this new code in the template:
<form method="post" enctype="multipart/form-data">
b) and if the widget support the $HTTP_POST_FILES sintax
c) and if the url to upload the file is correct:
d)And if I have to do domethig more to adapt the code to the new widget.

Than you very much!

More information about the Chameleon mailing list