0

I am currently using <input type="file"> to post a file. Since I cant specify the value for

<input id="content" type="file"> and have to manually browse for the file, I want to know if I can specify the path using PHP Curl.

will the server read $_POST["content"]

user478636
  • 3,304
  • 15
  • 49
  • 76
  • 1
    It isn't clear what you are trying to achieve. Are you trying to write a PHP program that will make an HTTP request and include a file encoded using multipart/form-data in the request? Thus bypassing the form itself altogether? – Quentin Nov 14 '11 at 10:37
  • A related question just asked by the same user: http://stackoverflow.com/questions/8120084/changing-value-of-input-type-file – thirtydot Nov 14 '11 at 10:37
  • @Quentin Yes thats what i'm trying to do – user478636 Nov 14 '11 at 10:40
  • @Col. Shrapnel — This appears to be a different question. The last one was "How can I prefill a file input?", this is "How can I post a file using PHP instead of a browser?" (Presumably with PHP running on the same machine as the file is starting on). – Quentin Nov 14 '11 at 11:45
  • @Col. Shrapnel Read the question before jumping to any conclusions. – user478636 Nov 14 '11 at 12:59
  • @Quentin too many assumptions :) What makes you become an advocate for the OP? – Your Common Sense Nov 14 '11 at 13:22

1 Answers1

1

Yes you can do it this way:

$post_params = array();
$post_params['file'] = '@'.'demo/testfile.txt';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);

the @ is really important to specify that this is an actual file to curl

You will receive the file through the $_FILES super global as if you did a rel form

$_FILES['file']

Hope it helps

To answer your question you need the absolute path on your filesystem

inkubux
  • 236
  • 2
  • 11
  • demo/testfile.txt is the relative path or absolute path? my file exists in c:\abc.doc – user478636 Nov 14 '11 at 10:42
  • 1
    I don't know why this got downvoted (unless it was due to the missing `curl_exec`). I would upvote if I was more familier with PHP's cURL library and could be more certain it was right. – Quentin Nov 14 '11 at 11:47
  • If that is true (I'm not the downvoter), then the question makes a 540 degree turn in terms of technologies in use. @user478636: Have you intended that with your question? – Boldewyn Nov 14 '11 at 12:16
  • To answer your question you need the absolute path on your filesystem – inkubux Nov 14 '11 at 12:41