• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1237
  • Last Modified:

AJAX PHP upload image as blob

I use an HTML form to call a javascript function that uses a PHP script to upload the image file chosen on the form to a MySQL database as a blob.

I use firebug to debug the output and the PHP output just says empty array and it cannot find the variables:
array(0) {
}
<br />
<b>Notice</b>:  Undefined index: userfile in <b>C:\wamp\www\portal\upload.php</b> on line <b>6</b><br />

Firstly this is my AJAX code - say if the PHP or HTML is required please.
Cheers anyone


var file = document.getElementById("userfile").value;
	var filename = document.getElementById("name").value;
	connection.open("POST", "upload.php", true);
	connection.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	connection.setRequestHeader("Content-length", file.length);
	connection.setRequestHeader("connection", "close");
	connection.send(file);

Open in new window

0
Johny_Brav0
Asked:
Johny_Brav0
  • 2
2 Solutions
 
leakim971PluritechnicianCommented:
0
 
leakim971PluritechnicianCommented:
0
 
mattibuttCommented:
I don't think you should store image in the database instead store a reference
0
 
Johny_Brav0Author Commented:
If I stored a reference then I could upload details via the GET method - something I think I could do.
Need to have a look at tutorial posted before though.
Cheers
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now