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"]

6
  • 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? Commented Nov 14, 2011 at 10:37
  • A related question just asked by the same user: stackoverflow.com/questions/8120084/… Commented Nov 14, 2011 at 10:37
  • @Quentin Yes thats what i'm trying to do Commented Nov 14, 2011 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). Commented Nov 14, 2011 at 11:45
  • @Col. Shrapnel Read the question before jumping to any conclusions. Commented Nov 14, 2011 at 12:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

demo/testfile.txt is the relative path or absolute path? my file exists in c:\abc.doc
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.
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?
To answer your question you need the absolute path on your filesystem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.