0

I have been able to successfully select an image and preview on iframe. I would like now to be able to take that previewed Image and upload into mysql table column as a Blob. I know that it is not in my best interest to upload images into database, but for my project it is in my best interest and as there will only be a limited amount of images to ever be uploaded. This is the code at where I am at. I have been able to upload image using another form but just cannot combine the scripts to work. Here is a working example of what i have so far, now i would like to take that previewed image and upload SampleApp

IFRAME

<img src="" id="image">
<input id="input" type="file" onchange="handleFiles()">

JAVASCRIPT

<script>
var img = document.getElementById("image");
var width = 400;
function handleFiles() {
var filesToUpload = document.getElementById('input').files;
var file = filesToUpload[0];
var reader = new FileReader();
reader.onload = function(e) {
img.onload = function() {
if (this.naturalWidth > width) {
this.width = width;
}
}
img.src = e.target.result;
}
reader.readAsDataURL(file);
}
</script>

CONNECTION

$con = mysqli_connect('****','*****','****','DBNAME') or die('Unable To connect');
$sql = "insert into images (image) values(?)";
INOH
  • 365
  • 2
  • 9
  • 27
  • Look into https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest with https://developer.mozilla.org/en/docs/Web/API/FormData for the javascript, and then look into http://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to for php – Isaac Aug 11 '16 at 00:16
  • is there away to take my whole script and create a php script that i can post on my server and be able to capture the previewed image – INOH Aug 11 '16 at 00:24
  • i have placed a SampleApp above to understand what i am trying to acchomplish. – INOH Aug 11 '16 at 00:32
  • Sorry wrong link in previous comment http://stackoverflow.com/a/38829952/267540 – e4c5 Aug 11 '16 at 00:36
  • thanks for the input, i would like to store images in another folder and add hyperlink to image in column, but was having hard time trying to retrieve images from link in Navicat – INOH Aug 11 '16 at 00:44

0 Answers0