Solved

AJAX PHP upload image as blob

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

18 Experts available now in Live!

Get 1:1 Help Now