How I can submit a file image using curl?

  • tiagodjm2
    Asked on August 18, 2020 at 10:54 AM

    I have a jotform and I am trying to submit the form using Curl, but it is not working!


    Here is the link for the jotform:

    https://form.jotform.co/71168395598877

      

    I got the message the submission has been received, but the curl_file_create didn't work. Is there any way to fix this issue? 


    Here is the code:


    $linfox = $_POST['linfox'];


    $linfox = json_decode($linfox,false);


    for ($count = 0; $count <= count($linfox)-1; $count++) {


        foreach ($linfox[$count] as $key => $value) {


    if (stripslashes($key) == "q46_photoOf"){


      $data['temp_upload'][$key] = stripslashes($value); 


    //   $data[$key] = stripslashes($value);


    }else{


      if (stripslashes($key) != "file"){


    $data[$key] = stripslashes($value); 


      }else{


      $basename = pathinfo($value,PATHINFO_BASENAME);


      $url_remove = stripos($value,"files");


      $full_path = getcwd() . "/" . substr($value,$url_remove);


      $extension = "image/" . pathinfo($value,PATHINFO_EXTENSION);


    //$file = fopen ($value, 'w+');


          $file = curl_file_create($full_path,$extension,'IMG'.rand(1,10000000));


    //     $file = new CURLFile($full_path,$extension,'IMG'.rand(1,10000000));


      $data[$key] = $file;


      }


    }


        }




     if (!function_exists('curl_init')){


        die('Sorry cURL is not installed!');


    }


    $url = 'https://submit.jotform.co/submit/71168395598877/';


    $ch = curl_init();


    curl_setopt($ch, CURLOPT_URL, $url);


    curl_setopt($ch, CURLOPT_POST, $count);


    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data;'));


    curl_setopt($ch, CURLOPT_POST, true);


    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);


    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);




    curl_setopt($ch, CURLOPT_HEADER, FALSE);


    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);


    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);




    $result = curl_exec($ch);




    curl_close($ch);




    echo($result);


    echo("Success");


    }


    Jotform Thread 2520419 Screenshot
  • Bojan Support Team Lead
    Replied on August 18, 2020 at 12:10 PM

    Greetings.

    Please note that you need to create an API key to post submission data. You can click here for additional information.

    Let us know if you have any additional questions. 

  • tiagodjm2
    Replied on August 18, 2020 at 12:17 PM

    I don't need to create API to post submission. This already works without API. I just need to know how I upload files using curl. Can you please help me with it?   

  • Bojan Support Team Lead
    Replied on August 18, 2020 at 1:29 PM

    Can you please confirm, is other information successfully saved in the form? Are you unable to save only the image? You can also contact our API team using the following email:

    api@jotform.com

    They will be able to provide your more relative information. 

    Thank you for your cooperation. 

  • tiagodjm2
    Replied on August 18, 2020 at 1:57 PM

    Yes, the other information successfully saved in the form. I am not able to save only the image when I use curl. I posted all the information in the first question.  

  • jonathan
    Replied on August 18, 2020 at 4:20 PM

    We apologize for inconvenience. But please take note that the support system was meant for resolutions related to the Form Builder.

    Not all support members are programmers, or have knowledge related to curl programming.  You have higher chance of getting a resolution with our developers from the API team api@jotform.com . So we suggest contacting them instead.