File upload PHP

I'm trying upload file for PHP with SmartFile SDK, but this code don't upolad in test.txt, Instead uploaded an empty file with the name Array.

$rh = fopen("test.txt", "rb");
$rh2 = realpath("test.txt");
$response = $client->post("/path/data/", array("test.txt" => $rh));
var_dump( $response);

how to upload a file ??

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Can you verify that $rh is not false and that the file permissions are correct for test.txt?

    Reply Like
  • @Ryan Johnston: Yes

    Reply Like
  • PHP files copied it again, and now I get this error:

    Parse error: syntax error, unexpected '[' in .../Services/SmartFile/Client.php on line 98

    Reply Like
  • I managed to solve. This code works:

    ​        $asdf = array_keys($data);
            $asdf2 = array_values($data);
            $filename = $asdf[0];
            $rh =  $asdf2[0];
    Reply Like
  • Thanks for the update. I hope your finding helps someone else.

    Reply Like
Like Follow
  • 4 yrs agoLast active
  • 5Replies
  • 735Views
  • 2 Following