Add a image to a post published on a CPT from the front-end

After two days looking for the solution and fighting with the code, I found the solution:

As I suspected, the problem was reading the file ($image_data = file_get_contents($image);).

The first error was not included in the form enctype =" multipart / form-data " to send files and data simultaneously.

The second error was that images are not loaded by $_POST, if not the global variable $_FILES (In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES).

And the last error was that we have to move the file to the directory uploads to read it from there with move_uploaded_file( $_FILES['imagen-promociona']['tmp_name'], $uploadfile )

I hope at least help others.

Thanks