?
Solved

AJAX PHP upload image as blob

Posted on 2010-08-24
4
Medium Priority
?
1,157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

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

Expert Comment

by:leakim971
ID: 33524847
0
 
LVL 11

Assisted Solution

by:mattibutt
mattibutt earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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