-1

Here is my piece of code.

process.php

$image = $_POST['image'];

index.php

<script>
function save(){
  var image = document.getElementById('image').files[0].name;

  $.ajax({
    type: "POST",
    url: 'process.php',
    data: {
      image: image
    },
  });
}
</script>

<input type="file" class="custom-file-input" id="image" name="image">

This basically returns only the file name to database mysql, but I don't know how to move the file from folder A to folder B. Which is the folder A is where the origin of the image lives, the folder B is when I want to call the image, I go with the path of folder B.

Is it possible to move the image by $_POST not $_FILES? Because so far I only find the $_FILES.

1 Answers1

1

You will need to send image as data url:

<input type="file" accept="image/*" onchange="loadFile(event)">
<script>
var img = "";
  var loadFile = function(event) {
    var output = document.getElementById('output');
    img = URL.createObjectURL(event.target.files[0]);
  };
function save(){
  var image = img;
  $.ajax({
    type: "POST",
    url: 'process.php',
    data: {
      image: image
    },
  });
}
</script>

Php:

$image = $_POST['image'];//now you can save the data url in database also
Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30