How to upload image to another server like amazon etc using php CURL

For upload an image or any file to external server using php curl just refer below code. and change it according to your need.

$profile_image_string = '';
            if ( isset($_FILES['profile_image']) )
            {
                $tmpfile = $_FILES['profile_image']['tmp_name'];
                $filename = basename($_FILES['profile_image']['name']);
                $filetype = $_FILES['profile_image']['type'];
                $org_image_string =curl_file_create($tmpfile,$filetype,$filename);
            }

    $ch = curl_init();
                 $data = array('user_id'=>$_SESSION['student_id'],'firstname'=>$user_name,'gender'=>$gender,
                            'user_profile_pic'=> $org_image_string);
                 //echo $url = "server url for upload data";
                 $header = array('Content-Type: multipart/form-data');
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                curl_setopt($ch, CURLOPT_POST, true);  // tell curl you want to post something
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
                // For Debug mode; shows up any error encountered during the operation
curl_setopt($ch, CURLOPT_VERBOSE, 1);
                $output = curl_exec ($ch); // execute
                curl_close ($ch); // close curl handle

Comments

Popular posts from this blog

How to add image option in nav menu in wordpress

How to add a custom email functionality in woocommerce,wordpress for example new email template for shipping order

How to change user id on checkout page for assign order to different user in woocommerce wordpress