L
L
leistolz2016-03-28 13:08:39
PHP
leistolz, 2016-03-28 13:08:39

Why is the photo not uploaded to the Vkontakte server?

There is an address for uploading a photo, and a file to upload. The code is the following:

$post_params['file'.$i] = 'myscreenshot.png';
$ch = curl_init($upl_server);    
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);

the response is an empty field photo
{"server":630531,"photo":"[]","hash":"77218860c21bb21e05aee660553c10bc"}
As I understand it, the problem is in converting a photo for uploading to the server.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-03-28
@Sanasol

www.stackoverflow.com/a/17033048

P
Petr Flaks, 2016-04-01
@neluzhin

Before the filename you lost the dog. That is, you should have something like this:
For greater clarity, a piece of my code:

$ch = curl_init();
$parameters = array(
  "file1" => '@'.__DIR__.'/path/to/myscreenshot.png'
);
    
curl_setopt($ch, CURLOPT_URL, $upl_server);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$curl_result = curl_exec($ch);
curl_close($ch);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question