Jump to content

PHP Curl upload file


jazz

Recommended Posts

Hi,

 

I am dead in the water with this. I cannot discover the problem.

 

I am trying to upload a file with curl and also pass a text value. It refuses to work. :)

 

 

Here 's a test form:

http://85.17.135.223/test.php

 

<?php

if (!empty($_REQUEST)) {
var_dump ($_REQUEST);
}

?>

<html>
<body>
<form>
<input type="text" name="a" value="value1" />
<input type="file" name="file1" />
<input type="submit" /> 
</form>
</body>

 

And then there 's the php script.

 

$url = 'http://85.17.135.223/test.php';
$file = getcwd().'/'.'step3.php';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('type' => 'direct', 'file1'=>"@$file", 'a'=>'aaaaa1'));
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result = curl_exec ($ch);
echo curl_error($ch);
$info = curl_getinfo($ch);
var_dump($info);

 

Here are the headers:

POST /test.php HTTP/1.1 Host: 85.17.135.223 Accept: */* Content-Length: 10448 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------b64cdfea8248

 

 

It does not work like it does if you do in through the browser. No script output! How can I make this work?

 

 

Thank you!

Link to comment
Share on other sites

Thank you for your reply. I added it but to no avail. The Expect header did indeed disapear, but nothing more changed.

 

Here are the new headers:

POST /test.php HTTP/1.1 Host: 85.17.135.223 Accept: */* Content-Length: 10495 Content-Type: multipart/form-data; boundary=----------------------------4047ac8569bd

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.