Solved

AJAX PHP upload image as blob

Posted on 2010-08-24
4
1,101 Views
Last Modified: 2012-08-14
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
Comment
Question by:Johny_Brav0
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33524789
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33524847
0
 
LVL 11

Assisted Solution

by:mattibutt
mattibutt earned 250 total points
ID: 33526733
I don't think you should store image in the database instead store a reference
0
 

Author Comment

by:Johny_Brav0
ID: 33530553
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.NET AJAX callbacks to web service are becoming very popular and unavoidable these days. The feel that the user gets when only a part of the page is updated without even hindering the UI is the advantage that the callbacks offer. The wait for the…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question