This is the $_POST
Array
(
[name] => image.png
[type] => image/png
[tmp_name] => C:\xampp5\tmp\phpA637.tmp
[error] => 0
[size] => 16412
)
And here's the code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "2403",
CURLOPT_URL => "http://".cfg('api_ip').":2403/sk_group/update_profile_pic", //url
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n{\"groupId\":\"".$group."\",\"profile_pic\":\"".$name."\"}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"profile_pic\"; filename=\"".$file."\"\r\nContent-Type: ".$type."\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"SessionId: ".$_SESSION['session']."",
"VersionCode: ".cfg('version_code')."",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
redirect("/meme/me/group"."?msg=".urldecode('Update icon group succes')."&type_msg=success");
}
i want to know how to $file to the image for success upload, cause $_POST only display the filename not with the fullpath.
Update
this is the full function in controller i have
function one()
{
$filename = $_FILES['icon']['name'];
$filedata = $_FILES['icon']['tmp_name'];
$filetype = $_FILES['icon']['type'];
two($_POST['group'], $filename, $filedata, $filetype);
}
this function on my helper
function two($group, $name, $file, $type)
{
$cFile = new CURLFile($file,$type,$name);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "2403",
CURLOPT_URL => "http://".cfg('api_ip').":2403/sk_group/update_profile_pic",
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n{\"groupId\":\"".$group."\",\"profile_pic\":\"".$name."\"}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"profile_pic\"; filename=\"".$cFile."\"\r\nContent-Type: ".$type."\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"SessionId: ".$_SESSION['session']."",
"VersionCode: ".cfg('version_code')."",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
redirect("/meme/me/group"."?msg=".urldecode('Update icon group succes')."&type_msg=success");
}
}
still with same question like i asking..., where the file? and how to post it until success?