[Seaside] Multiple file upload with jquery ajax and FormData

Un-Seok unseokyeo at gmail.com
Fri Feb 22 17:28:31 UTC 2013


Hi Smalltalkers,

I am an absolute newbie to smalltalk (and seaside) in need of your great
wisdom on file upload.

What I am trying to do is allow users to drag a file (or files) from their
desktop and drop it to a <div> tag to trigger file upload.  I have it
working with php but not sure how to translate this to *smalltalk way*.

On the browser side I am doing the following using javascript (and jquery):
1. preventDefault() on both 'dragover' and 'drop' to prevent browser from
opening the file on drag and drop.
2. append each file to FormData :

   for (filename in filelist) {
      formData.append(filename, filelist[filename]);
    }

3. Then fire an ajax call with formData:

	$.ajax({
		*url: 'php/fileupload.php'*,
		data: formData,
		processDate: false,
		contentType: false,
		type: 'POST',
		success: function(data) {
			alert("File upload completed");
			removeAll();
		},
		error: function(a, b, c) {
			alert("Error: " + c);
		}
	});

But, I am lost when it comes to target url (in red) for this ajax request.

On the server side, I have a simple php that handles the request:

<?php
    foreach ($_FILES as $filename => $file) {
      if ($_FILES[$filename]["error"] > 0) {
        echo "Error: " . $_FILES[$filename]["error"];
      } else {
        move_uploaded_file($_FILES[$filename]["tmp_name"], "upload/" .
$_FILES[$filename]["name"]);
      }
    }
?>

Your help will be greatly appreciated.



Un-Seok



--
View this message in context: http://forum.world.st/Multiple-file-upload-with-jquery-ajax-and-FormData-tp4671533.html
Sent from the Seaside General mailing list archive at Nabble.com.


More information about the seaside mailing list