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

  • Home
  • SEARCH
  • 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 6561051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:32:23+00:00 2026-05-25T13:32:23+00:00

I am having troubles while trying to post some datas with one file (an

  • 0

I am having troubles while trying to post some datas with one file (an image) that I want to upload. Using PHP 5.3.3 and CURL 7.20.0.

Here is the php script (the image is in the same folder I have checked that the path is valid).

function curl_post_request($url, $data, $referer='') {
$data = http_build_query($data); // seems to be required arrays should'nt be supported ? whatever.
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_REFERER, $referer);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($c, CURLOPT_HEADER, $headers); 
curl_setopt($c, CURLINFO_HEADER_OUT, true);
curl_setopt($c, CURLOPT_VERBOSE, true);
$output = curl_exec($c);
var_dump(curl_getinfo($c, CURLINFO_HEADER_OUT));
//var_dump($data);
if($output === false) trigger_error('Erreur curl : '.curl_error($c),E_USER_WARNING);
curl_close($c);
return $output;
}

if(isset($_GET['GO'])) {

$data = array(
'pic1' => "@".realpath('image.jpg'),
'postedvar1' => 'test1',
'postedvar2' => 'test2'
);
$url = 'http://localhost/test/index.php';
$a = curl_post_request($url, $data);
var_dump($a);

} else {

print_r($_POST);
print_r($_FILES);
}

What am I missing? Is this working for you guys?

The curl request seems to be fine, take a look at the following results :

    headers = POST /test/test.php HTTP/1.1
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
    Host: localhost
    Accept: */*
    Referer: 
    Content-Length: 82
    Content-Type: application/x-www-form-urlencoded

    HTTP/1.1 200 OK
    Date: Sun, 11 Sep 2011 19:46:18 GMT
    Server: Apache/2.2.16 (Win32) PHP/5.3.3
    X-Powered-By: PHP/5.3.3
    Content-Length: 138
    Content-Type: text/html

    $_POST = Array(
    [pic1] => @C:\wamp\www\test\image.jpg
    [postedvar1] => test1
    [postedvar2] => test2
    )
    $_FILES = Array()
  • 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-05-25T13:32:24+00:00Added an answer on May 25, 2026 at 1:32 pm

    To use the @filepath method of specifying a file to upload, the value for the CURLOPT_POSTFIELDS option must remain as an array.

    The first line of your curl_post_request() function turns the array into a urlencoded string.

    See the description of CURLOPT_POSTFIELDS in the manual — http://php.net/curl-setopt

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

Sidebar

Related Questions

I'm trying to create a tab delimited file with PHP and having some troubles.
I was having troubles earlier while trying to declare a ChangeAction parameter in a
I'm having some trouble with NHibernate, while trying to remove an object describing a
I was having some trouble running some Ruby scripts. While trying to get these
I've been having some trouble lately while trying to learn how to do an
I am having a trouble while trying to create an entity with a custom
I'm having trouble with making a subdomain to my Windows computer while using AJP
I'm having troubles using Blend with my visual studio solution. In Runtime, and compile
im currently having troubles on my codes in C#. I want to split strings
I've been having troubles trying to figure out how to solve a function. I've

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.