Q: Can't quite get uploading a file via Curl in PHP to work I've been searching for a while now on how to upload a file via curl in PHP... I've found that all you need to do is use the absolute path and put the "@" in front of the path/filename, and it should work.  Not the case with me.  Here is my code for posting the file:
$url = "http://my_url/testing.php";

$partner_key = "XXXX";
$secret_key = "YYYY";
$resume_file = realpath("resumes/$newfilename");
$first_name = $_REQUEST['apply_firstname'];
$last_name = $_REQUEST['apply_lastname'];
$email = $_REQUEST['apply_email'];

$content  = "partner_key=$partner_key&";
$content .= "secret_key=$secret_key&";
$content .= "resume_file=@$resume_file&";
$content .= "first_name=$first_name&";
$content .= "last_name=$last_name&";
$content .= "email=$email";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response = curl_exec($ch);
curl_close($ch);

print $content . "<br>";
print $response;

And here is the response I'm getting.  It looks like the whole path is getting sent as a value in the curl request (even with the "@" attached), but no actual file information is being passed that I can grab in the $_FILES array.
Upload error!
File Info: 
Array
(
)


Array
(
    [partner_key] => XXXX
    [secret_key] => YYYY
    [resume_file] => @/var/www/html/docroot/resumes/resume-jsdkfjsdf-gmail-com-20140429015617.doc
    [first_name] => john
    [last_name] => johnson
    [email] => jsdkfjsdf@gmail.com
)

Is there something that I'm missing?  Maybe a curlopt I haven't set?

A: The problem is that the '@' character is not the first character in the $content string. Furthermore, the curl_setopt docs say that using '@' in postfields is deprecated in PHP 5.0
The solution is to use CURLFile and to let $content be an array:
$curl_file_upload = new CURLFile($resume_file);
$content = array("partner_key" => $partner_key,
        "secret_key" => $secret_key,
        "resume_file" => $curl_file_upload,
        "first_name" => $first_name,
        "last_name" => $last_name,
        "email" => $email);

and later
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);

Hope this helps.

A: I've finally figured it out!
In order for the file upload to work, my post fields have to be constructed as an array and not just a url string.
So I changed this:
$content  = "partner_key=$partner_key&";
$content .= "secret_key=$secret_key&";
$content .= "resume_file=@$resume_file&";
$content .= "first_name=$first_name&";
$content .= "last_name=$last_name&";
$content .= "email=$email";

To this:
$content = array(
  'partner_key' => $partner_key,
  'secret_key' => $secret_key,
  'resume_file' => "@" . $resume_file,
  'first_name' => $first_name,
  'last_name' => $last_name,
  'email' => $email
);

And it's working great now!
