I have this line:
move_uploaded_file($_FILES["img"]["tmp_name"], "uploads/" . "$img_name");
That used to work when I received the image through a direct POST (without JSON.stringify the content). Now I'm sending the ajax with the image inside of an array stringified, so I'm getting the contents of the array in the PHP file in this way:
$unstringified = json_decode(file_get_contents("php://input"), true);
And then I use:
$title = $unstringified["title"];
$content = $unstringified["content"];
$img = $unstringified["img"];
The problem is that now the move_uploaded_file stop working (seems to be no error but the image doesn't appear saved in the folder anymore). I tried some options like these, but didn't work.
move_uploaded_file($unstringified["img"]["tmp_name"], "uploads/" . "$img_name");
move_uploaded_file($_FILES[$unstringified["img"]]["tmp_name"], "uploads/" . "$img_name");
Any idea to solve this? Should I "convert" the image in any format until putting it in the array I will stringify? or I have to get the image in another way in the PHP file?
Thanks a lot in advance. Leandro.