Solved

AJAX PHP upload image as blob

Posted on 2010-08-24
4
1,077 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello World !, Thanks : My Sincere thanks to @Michael Male who encouraged me to write an article on this in my  blog (http://scribblejava.wordpress.com). Introduction:       There are several technical issues a developer may face in his…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now