S
S
santavits2018-03-20 12:04:09
PHP
santavits, 2018-03-20 12:04:09

Why doesn't uploading photos via VK API work if I use cron?

Faced such a problem, I'm uploading photos to the VK album, via api.
So when you run the script via a direct link through the browser, everything works fine, the photos are loaded, I put it on cron and everything does not load photos_list returns empty.
Here is the code, can anyone tell me what the problem is

$imge = "/images/55391447-13.jpg";

$image_path = dirname(__FILE__).$imge;
$post_data = array("file1" => '@'.$image_path);

// получаем урл для загрузки
 $url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id=".$album_id."&group_id=".$group."&v=".$v."&access_token=".$token);
$url = json_decode($url)->response->upload_url;
print_r($url);

// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$resultx = json_decode(curl_exec($ch),true);
//print_r($resultx);

Thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PashaWNN, 2018-03-20
@PashaWNN

Perhaps it's a matter of write permissions to where the photos should be saved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question