Trying to make class.upload.php with Ajax but i need help

See all posts Reply

Trying to make class.upload.php with Ajax but i need help new!
by Alex, 11 years ago
I have this form :
<form id="the-form" action="upload.php" enctype="multipart/form-data">
  <input id="the-file" type="file" size="32" name="file[]" value="">
  <input id="the-file" type="file" size="32" name="file[]" value="">
  <input id="the-file" type="file" size="32" name="file[]" value="">
</form>

And i have this Ajax script:
var fileInput = document.getElementById('the-form');
  form.onsubmit = function() {
  var file = fileInput.files[0];
  var formData = new FormData();
  formData.append('file', file);
					  	
  var xhr = new XMLHttpRequest();
  // Add any event handlers here...
  xhr.open('POST', form.getAttribute('action'), true);
  xhr.send(formData);
  return false; // To avoid actual submission of the form
}

I'm trying to make an image/s upload without refreshing the page with the class.upload.php but i can't solve it. Every time i do this i'm getting some errors and the main error is :
Notice: Undefined index: file in C:\wamp\www\OP\admin\test\upload.php on line 6
Warning: Invalid argument supplied for foreach() in C:\wamp\www\OP\admin\test\upload.php on line 6


Any help with this issue? any suggestions or past experiences that could solve this is welcome. Thanks.Reply
Re: Trying to make class.upload.php with Ajax but i need help new!
by colin, 11 years ago
Well, it all depends on your PHP script. You need to instantiate the class with code like this:
$handle = new upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);

See the examples provided in the package, it should help you out.Reply