FileUpload Problems

Forums » General discussion
     » FileUpload Problems

2008/08/14 00:01

Hi there,

I'm facing some trouble implementing a file upload test case with DynarchLib. Probably I'm  missing some thing, but I can't find it!!!!

This piece of code is running on the " Run Code Samples" dialog:

//DIALOG
var dlg = new DlDialog({ title: "Form example", quitBtn: "destroy" });

//MAIN AREA
var vbox = new DlVbox({ parent: dlg, borderSpacing: 5 });

//FIELDGRID
var fs = new DlFieldGrid({ parent: vbox });

//ENTRY FIELD
var fldFile = new DlEntry({name:'file', id:'file', type:'file'});

fs.addField({label: "FileName:",widget:fldFile});

vbox.addSeparator();

//SIMULATING THE SUBMIT BUTTON.. Can I do it???
var btn = new DlButton({ parent: vbox, label: "Send File" });
btn.addEventListener("onClick", function() {
        //var val = DlJSON.encode(fs.getValue()); //Don't work
        var val = fldFile.getValue(); //Don't work too
        new DlRPC({ url : "http://localhost/devel/upload.php",
            data : val,
            callback: showResult,
          }).call();
});
dlg.centerOnParent();
dlg.show();

function showResult(answer){
                 if (answer.success){
                   print ("!!!SUCCESS!!!");
                   print(answer.text);
                 } else {
                   alert ("!!!FAILED!!!" );
                 }

};

Here is the server side script (PHP):

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?>

And this a simple HTML file to test the upload script:

<html>
<body>

<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

Can anyone help me, pleaseeeeeee?


Tks in advance, DonDudles