L
L
leistolz2016-03-28 19:48:34
PHP
leistolz, 2016-03-28 19:48:34

Why is the Photo field returned empty?

There is this code:

$post_params = array( 
'photo'=> 'myscreenshot.png'
);
$ch = curl_init($serverArray);    
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$response = curl_exec( $ch );
curl_close( $ch );
echo($response);

In theory, the myscreenshot.png file should go to the server, but this does not happen, which is why VK sends me a response: {"server":630531,"photo":"[]","hash":"77218860c21bb21e05aee660553c10bc"}
С empty "photo" field, which should not be empty.
I tried a lot of ways, none of them worked. As I understand it, the problem is in the array of the photo file, either the path must be fully specified before it, or converted in another way. I don't have the strength to deal with this crap anymore.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton B, 2016-03-28
@bigton

$post_params = array( 
'photo'=> '@./myscreenshot.png'
);

O
OnYourLips, 2016-03-28
@OnYourLips

Use this to send a file using CURL:
php.net/manual/en/class.curlfile.php Better
yet, learn how to use Guzzle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question