Good day to all!

The $photos line is stored with a photo.

When displaying via echo displays correctly:

 'file1' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/089dd91706ec5a801102fc.jpg','file2' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/40fc3c94aec04cde3fa9b8.jpg','file3' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/1edb44ca42ad51597678a2.jpg','file4' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/f9cbf3efd9a00b1f0fbb6b.jpg' 

Next, send

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $VKuploadUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array($photos)); $otvet = curl_exec($ch); curl_close($ch); 

and in response [photo] => []

what if

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $VKuploadUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array('file1' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/089dd91706ec5a801102fc.jpg','file2' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/40fc3c94aec04cde3fa9b8.jpg','file3' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/1edb44ca42ad51597678a2.jpg','file4' => '@/var/www/xdrent/data/www/test.biz/upload/lexx/25397178_118034/f9cbf3efd9a00b1f0fbb6b.jpg')); $otvet = curl_exec($ch); curl_close($ch); 

That sends ok

What is the problem?

  • Array of arrays? Do not joke? - maxleo
  • curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ photos); -? - lexx
  • 1. So you see what you send in each case - in the first case you send an array of one line (and this is NOT a valid picture), in the second case you send an array of valid images. 2. And why do all the pens do? SDK did not try to use? - BOPOH

2 answers 2

Replace the line:

 curl_setopt($ch, CURLOPT_POSTFIELDS, array($photos)); 

per line:

 curl_setopt($ch, CURLOPT_POSTFIELDS, $photos); 

And everything will work!

UPD
As I understand it, the $photos variable is your string, for this reason your code does not work. You need at the stage of formation of the paths to the pictures to write them into an array.
As I understand it, you have a cycle of pulling pictures from the database.

 //Начало цикла $photos['file'.$i] = 'ПУТЬ ДО КАРТИНКИ'; //Конец цикла 

UPD2

The correct code is:

 $photos = array(); for ($k = 0; $k < count($wall[$i]->attachments); $k++) { $nom = $k + 1; $photos['file'.$nom] = '@' . $dir . $newfile; } 

And then use the line: curl_setopt($ch, CURLOPT_POSTFIELDS, $photos); .

  • (does not want to - lexx
  • If $ photos is a string, then of course it won't work - MarinaVoin
  • At the stage of forming a string, you need to form an array! And then pass it the way I wrote above - MarinaVoin
  • I apologize for the audacity, you can example. I try this: for ($ k = 0; $ k <count ($ wall [$ i] -> attachments); $ k ++) {$ nom = $ k + 1; $ photos. = "'file". $ nom. "' => '@". $ dir. $ newfile. "',"; } - lexx
  • Wrote, see UPD2. If the answer is correct, then do not forget to mark it as correct! - MarinaVoin

$ photos - string or array? Arrays through echo are not displayed, in my opinion.

  • Sealed String - lexx