5

When I trying to upload a file with php and curl, an error occurs "failed creating formpost data". I know that error occur when file path incorrect

test.php
...
$postcontent['files'] = '@test.jpg';
...

test.php and test.jpg in the same folder. But if I change path to physic path, code run well

test.php
...
$postcontent['files'] = '@F:\xampp\htdocs\upload\test.jpg';
...
1
  • 1
    bugs.php.net/bug.php?id=50060 - maybe this is why. I had this problem too and I did the following test. I replaced the '@' with '' and the error disappeared. Commented Nov 5, 2012 at 2:01

1 Answer 1

7

Try to always use an absolute path, like you did in your second example, which works.


Of course, you do not want to hard-code that physical path, so you will want to use either :

  • dirname(__FILE__) to get the path to the directory that contains the file in which this is written
  • Or, with PHP >= 5.3 : __DIR__ which gives exactly the same path.


So, in your case, you'd probably use something like :

$postcontent['files'] = '@' . __DIR__ . '/test.jpg';

Or, with PHP < 5.3 :

$postcontent['files'] = '@' . dirname(__FILE__) . '/test.jpg';
Sign up to request clarification or add additional context in comments.

Comments

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.