Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:24:26+00:00 2026-06-18T00:24:26+00:00

I have the following C code: int main(int argc, char* argv[]) { CURL *curl;

  • 0

I have the following C code:

int main(int argc, char* argv[])
{
  CURL *curl;
  CURLcode res;
  struct stat file_info;
  double speed_upload, total_time;
  FILE *fd;

  fd = fopen(argv[1], "rb"); /* open file to upload */
  if(!fd) {

    return 1; /* can't continue */
  }

  /* to get the file size */
  if(fstat(fileno(fd), &file_info) != 0) {

    return 1; /* can't continue */
  }

  curl = curl_easy_init();
  if(curl) {
    /* upload to this place */
    curl_easy_setopt(curl, CURLOPT_URL,
                     "http://www.website.com/index.php");

    /* tell it to "upload" to the URL */
    curl_easy_setopt(curl, CURLOPT_POST, 1L);

    /* set where to read from (on Windows you need to use READFUNCTION too) */
    curl_easy_setopt(curl, CURLOPT_READDATA, fd);

    /* and give the size of the upload (optional) */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                     (curl_off_t)file_info.st_size);

    /* enable verbose for easier tracing */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK) {
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    }
    else {
      /* now extract transfer info */
      curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
      curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);

      fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
              speed_upload, total_time);

    }
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

and the following PHP code:

<?php
header('Access-Control-Allow-Origin: *');

if ($_SERVER['REQUEST_METHOD'] == 'POST' )
{
    if( isset( $_FILES["file_entry"] ) )
    {
    print "file ok";
    }
    else
    {
    print "no file sent";
    }
}
else
{
    print "No post method" . $_SERVER['REQUEST_METHOD'];
}
?>

and html code:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
</head>
<body>
<form action="index.php" enctype="multipart/form-data" method="post">
    <input type="file" name="file_entry"/>
    <input type="submit" value="enviar"/>
</form>
</body>
</html>

If I try to send the file by html, it works fine, but not when I use C and cURL.
Because I don’t know how I can send “file_entry”. How can I emulate submit “file_entry” with C cURL like html does? I try use CURLOPT_POSTFIELDS, but don’t work.

Anyone can help me ?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:24:27+00:00Added an answer on June 18, 2026 at 12:24 am

    This is because your server end expects a “multipart/form-data” POST and you send a regular “url-encoded” one.

    You should instead look into for example the multi-post.c example or the curl_formadd() documentation.

    Alternatively you change the server end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: int main(int argc, char** argv) { onelog a; std::cout
I have the following code: int main(int argc, char *argv[]) { if(strcmp(argv[1],-e)==0) { //perform
Suppose you have the following code: int main(int argc, char** argv) { Foo f;
I have the following code: #include <stdio.h> main(int argc, char *argv[]) { int n,st;
I have the following code: #define INPUT_FILE -i int main(int argc, char* argv[]) {
I have an issue with the following code: #include <QtGui/QImage> int main(int argc, char*
I have following code: #include <cstring> #include <boost/functional/hash.hpp> #include <iostream> int main(int argc, char
In the following code: int main(int argc,char * argv[]){ int * ptr; ptr =
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.