以下は、画像と登録番号を送信しているcurlのコードです...
char url[]="xyz.com/imm/application.php?";
char curlErr[2*CURL_ERROR_SIZE]={0};
CURL *curl=NULL;
struct curl_httppost *post=NULL, *last=NULL;
FILE *fp=NULL;
fp = fopen(SEND_DATA_RESPONSE_PATH, "w");
if (fp == NULL) {
printf("%s:unable to open %s\n", __func__, SEND_DATA_RESPONSE_PATH);
return -1;
}
curl = curl_easy_init();
if (!curl) {
printf("%s:unable to init curl\n", __func__);
return -2;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FILE, fp);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "registerNumber",
CURLFORM_COPYCONTENTS, studentDetails.regNo, CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "studentPhoto",
CURLFORM_FILE, PHOTO_PATH, CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "parentImage",
CURLFORM_FILE, SIG_PATH, CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlErr);
res=curl_easy_perform(curl);
curl_formfree(post);
curl_easy_cleanup(curl);
if (res != 0) {
printf("%s:Curl error: %s\n", __func__, curlErr);
return -3;
}
return 0;
この後..application.phpページで、rer番号と画像を取得し、この画像をサーバーにアップロードしようとしています。しかし、move_uploaded_fileが機能していません...
$regNum=$_POST['registerNumber'];
$std_img_tmp_name=$_FILES['studentPhoto']['tmp_name'];
$std_img_name = $_FILES['studentPhoto']['name'];
$std_img_fileSize = $_FILES['studentPhoto']['size'];
$std_img_fileType = $_FILES['studentPhoto']['type'];
$sig_tmp_name=$_FILES['signatureImage']['tmp_name'];
$sig_name = $_FILES['signatureImage']['name'];
$sig_fileSize = $_FILES['signatureImage']['size'];
$sig_fileType = $_FILES['signatureImage']['type'];
$target_path = "../uploads/";
$student_img_name=$target_path.$std_img_name;
$signature_name=$target_path.$sig_name;
$photo_status=move_uploaded_file($_FILES["studentPhoto"]['tmp_name'], $student_img_name);
$sig_image_status=move_uploaded_file($_FILES["signatureImage"]["tmp_name"], $signature_name);
if($photo_status==FALSE || $sig_image_status==FALSE)
{
echo "<result><error>Unable to upload photo</error></result>";
exit();
}
エラーが発生します...これを解決する方法...