1

I have included the javascript in my project and FilePond works great on the FrontEnd, as you can see below:

enter image description here

Here is the code in my HTML: When I submit the form this is what I get for filepond: enter image description here Code: https://snipsave.com/user/viktorgavrilovic/snippet/TpgWPYaBBmWe1N44YO/

Now, how can I save the image to a folder, let's say: C:/temp/?

I know that I have to decode because the data is base64 encoded, here is my PHP so far, with decoded format:

$filepond = $_POST["filepond"];
$json_decoded = json_decode($filepond[0], true);
var_dump($json_decoded);

and this is what I get from the decoded format: enter image description here Code: https://snipsave.com/user/viktorgavrilovic/snippet/u3Th8eqrzvmq6IAWAI/

Could you please tell me what should I do next in order to save the image in a folder and in a MySql DB? Thank you very much!

gr8pr0gramm3er
  • 103
  • 1
  • 10
  • If you're just getting started with PHP and want to build applications, I'd strongly recommend looking at various [development frameworks](https://www.cloudways.com/blog/best-php-frameworks/) to see if you can find one that fits your style and needs. They come in various flavors from lightweight like [Fat-Free Framework](https://fatfreeframework.com/) to far more comprehensive like [Laravel](http://laravel.com/). These give you concrete examples to work from and guidance on how to write your code and organize your project's files, and come with tools to manage image uploads. – tadman Mar 11 '20 at 17:40
  • @tadman thank you for the comment, I am not starting with PHP now, I do have some experience building PHP applications as well as image uploads, what I do not know is on how to upload this exact image that I am getting from filepond, since the data is encrypted and I am not receiving it as a normal file/image. So if you have any idea on how to do it, it would mean a lot to me and help me :) – gr8pr0gramm3er Mar 11 '20 at 17:44
  • 1
    "the data is encrypted"...no, it's just encoded. Anyway this might help you: https://stackoverflow.com/questions/11511511/how-to-save-a-png-image-server-side-from-a-base64-data-string (or google "php decode base64 and save" to get quite a few other results) – ADyson Mar 11 '20 at 17:53
  • 2
    It'd help if you posted the decoded format as text so we can work with it, as right now it's this smudge of an image which means we really can't test anything on it. – tadman Mar 11 '20 at 17:54
  • @tadman here is a link where you can access the encoded data that I receive from the POST: https://snipsave.com/user/viktorgavrilovic/snippet/TpgWPYaBBmWe1N44YO/ and here you can access the decoded data: https://snipsave.com/user/viktorgavrilovic/snippet/u3Th8eqrzvmq6IAWAI/ – gr8pr0gramm3er Mar 11 '20 at 18:17
  • It'd really help if you include that in the body of the question and keep it self-contained. Off-site links and resources may expire or be inaccessible to people trying to answer your question. – tadman Mar 11 '20 at 20:03
  • @tadman as you can see how long is the "data" inside the POST request, that it freezes the whole stackoverflow page when I try to copy it. If you have any idea on how to resolve it, you are welcome :) – gr8pr0gramm3er Mar 11 '20 at 20:17
  • 1
    That's where having a more minimal example helps. Like a 1x1 pixel image, those are usually super small and take a few lines to paste. – tadman Mar 11 '20 at 20:30
  • Is it possible that the junk in `"data"` is just [Base64 encoded](https://en.wikipedia.org/wiki/Base64)? It sure looks like a JPEG header there (`FFD8...`) when encoded. – tadman Mar 11 '20 at 20:32
  • 1
    This is the function you need to turn that data into a file: https://github.com/pqina/filepond-server-php/blob/master/submit.php#L34 – Rik Mar 12 '20 at 08:18

0 Answers0