0
I’m trying to send an image along with the notification via php, the notification is sent normally, but the image will not. Can you tell me what’s wrong with that code?
<?php
if (isset($_POST['titulo'])) {
    move_uploaded_file($_FILES['Imagem']['tmp_name'], 'Imagens/' . $_FILES['Imagem']['name']);
    function sendMessage()
    {
        $content = array(
            "en" => $_POST['mensagem']
        );
        $imagem = $_FILES['Imagem'];
        $headings = array("en" => $_POST['titulo']);
        $fields = array(
            'app_id' => "2ac0abda-15ae-4d27-aa5b-da8400941d97",
            'included_segments' => array('All'),
            'contents' => $content,
            'headings' => $headings,
            //'small_icon'
            'large_icon' => 'https://www.iconexperience.com/_img/v_collection_png/64x64/shadow/ok.png', //  Ok
            'big_picture' => $imagem, //  Ok
            // 'android_led_color' => "FF0000FF",
            //'notification[android_accent_color]' => "FF0000FF",
        );
        $fields = json_encode($fields);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
            'Authorization: Basic M2I5MDEzYTItN2VkYS00YTVhLWE0OWMtMzY3MzNkOTU3NWQ3'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
    $response = sendMessage();
    $return["allresponses"] = $response;
    $return = json_encode($return);
}
						
You moved the image (using the function
move_uploaded_file) before executing thecURL. The value to assign the variable$imagemwould be'Imagens/' . $_FILES['Imagem']['name']and not$_FILES['Imagem']; or if you just want the name of the image:$_FILES['Imagem']['name'].– Filipe Moraes
It didn’t work, the fact that I wore Onesignal gets in the way of something ?
– Aluisio Pereira