0

I am trying to execute this curl as shown below. but when executing it gives me error as

( ! ) Notice: Array to string conversion in C:\wamp\www\XXX\workerInsBusiness.php on line 75
Call Stack
#   Time    Memory  Function    Location
1   0.0017  269704  {main}( )   ..\workerInsBusiness.php:0
2   0.0073  285048  curl_setopt_array ( )   ..\workerInsBusiness.php:75

Complet Source

$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$city_ref=$_POST['cityselect'];
$area_ref=$_POST['areaselect'];
$address=$_POST['address'];
$region=$_POST['region'];
$dist=$_POST['dist'];
$pincode=$_POST['pin'];
$category=$_POST['category'];
$shopname=$_POST['shopname'];
$url=$_POST['url'];
$businessdetails=$_POST['busdetails'];
$score=$_POST['score'];
$file=$_FILES['img']["name"];
$verification=$_POST['verification'];

$dt = date("ydmhms");
if(!$file)
{
    $newfn="Noimage";
}
else
{
    $name=explode(".",$file);

    $newfn = 'kdial_'.$dt.".".$name[1];
}

if($_FILES["img"]["error"]>0)
{
    $_SESSION["E_MESSAGE"]="Problem while uploading file, Please try again";
    header("Location: home.php");
}
else
{
    if((($_FILES["img"]["type"]=="image/jpeg")||($_FILES["img"]["type"]=="image/png"))&&($_FILES["img"]["size"]<=3145728))
    {//&&($_FILES["UFILE"]["size"]>50000)){
    //echo "File is ready to upload";
        if(file_exists("uploads/".$_FILES["img"]["name"]))
        {
            $_SESSION["E_MESSAGE"]="File already exist,  Please try again";
            header("Location: home.php");
        }
        else
        {
            move_uploaded_file($_FILES["img"]["tmp_name"],"uploads/".$newfn); 

                $ch = curl_init();
                $curlConfig = array(
                    CURLOPT_URL            => "http://localhost:91/XXXX/allServices/insertBusiness.php",
                    CURLOPT_POST           => true,
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_POSTFIELDS     => array(
                    'name' => $name,
                    'phone' => $phone,
                    'email' => $email,
                    'cityselect' => $city_ref,
                    'areaselect' => $area_ref,
                    'address' => $address,
                    'region' => $region,
                    'dist' => $dist,
                    'pin' => $pincode,
                    'category' => $category,
                    'shopname' => $shopname,
                    'url' => $url,
                    'busdetails' => $businessdetails,
                    'score' => $score,
                    'fn' => $newfn ,
                    'verification' => $verification,
                    )

                );
                curl_setopt_array($ch, $curlConfig);
                $result = curl_exec($ch);
                if (curl_errno($ch)) 
                {
                    // this would be your first hint that something went wrong
                    die('Couldn\'t send request: ' . curl_error($ch));
                } 
                curl_close($ch);
                //print_r("soham ".$result);
                $jsonobj = json_decode($result);
                print_r("json obj ".$jsonobj);
                exit();
            }
    }
    else
    {
        $_SESSION["ERROR"]="Invalid File";
        header("Location: home.php");
    }
}

file upload works properly. What is problem with executing this curl i searched a lot i found some thing that says u must use http_build_query() but i dont know how to use this

4
  • possible duplicate of PHP: curl_setopt_array gives notice "array to string conversion" Commented May 4, 2015 at 8:50
  • are there any arrays inside the elements assigned to CURLOPT_POSTFIELDS ? Commented May 4, 2015 at 8:51
  • i have updated my question their is no any array inside curlopt_postfields Commented May 4, 2015 at 8:58
  • its working, actually array was passing to $name variable because i used same variable name to create image name so i changed it and that worked now, thank you Commented May 4, 2015 at 9:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.