[Chameleon] RV: Problem with new widget - adapt php code
Ines
mleonsoft at yahoo.com.ar
Fri Apr 13 14:23:29 EDT 2007
-----Mensaje original-----
De: Ines [mailto:mleonsoft at yahoo.com.ar]
Enviado el: lunes, 26 de marzo de 2007 11:22
Para: chameleon at lists.maptools.org
Asunto: Problem with new widget - adapt php code
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.
PHP CODE:
----------------------------------------------------------------------------
-------
upfile.php:
--------------------
<form action="subearchivo.php" method="post" enctype="multipart/form-data">
<b>Enter an XML file: </b>
<br>
<input name="userfile" type="file">
<br>
<input type="submit" value="Submit">
</form>
---------------------------
subearchivo.php:
------------------------------------
<?
//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
<br><li>.</td></tr></table>";
}else{
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
"wmsviewer/geointegrator/htdocs/$name_file")){
//I rename the file to upload it to the the server with the name I want
rename("wmsviewer/geointegrator/htdocs/$name_file",
"wmsviewer/geointegrator/htdocs/archivo.xml");
echo "The upload is success.";
}else{
echo "Error to upload the file.";
}
}
?>
------------------------------------------------------
Template.html
--------------------------------------------------
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"
sube="bb"
imagetip="Search"
image="icons/icon_ok.png"
styleresource="NavButtons"
imagewidth="25"
SubmitOnClick="true"
toolset="nav"> <image state="normal"/> <image state="hover"/> <image
state="selected"/>
</cwc2>
-------------------------------------------------------
Widget:
---------------------------------------------
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
parent::ParseURL();
if ( $this->isVarSet( "NAV_CMD" ) &&
$this->getVar( "NAV_CMD" ) == 'Subexml' )
{
if ( $this->mszCoords == 'bb')
{
if ($this->isVarSet('userfile'))
{
$this->getVar('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
<br><li>.</td></tr></table>";
}else{
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
"wmsviewer/geointegrator/htdocs/$this->name_file")){
rename("wmsviewer/geointegrator/htdocs/$this->name_file",
"wmsviewer/geointegrator/htdocs/archivo.xml");
echo "The upload is success.";
}else{
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:
wmsviewer/geointegrator/htdocs/$this->name_file
d)And if I have to do domethig more to adapt the code to the new widget.
Than you very much!
Ines
More information about the Chameleon
mailing list