Приветствую, уважаемые! Срочно нужна ваша помощь, сам пока не понял в чем проблема. Поставил php 7.0.13 - перестало загружать фото, ранее на php5 нормально все работало. Код (Text): class vk { private $token; private $app_id; //ID группы или страницы пользователя private $group_id; public function __construct( $token, $app_id, $group_id ) { $this->token = $token; $this->app_id = $app_id; $this->group_id = $group_id; } //получаем данные со стены public function get_wall($count, $filter) { $data = json_decode( $this->execute( 'wall.get', array( 'owner_id' => -$this->group_id, 'count' => $count, 'filter' => $filter ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response; } //узнаем id группы public function get_group_id($name) { $data = json_decode( $this->execute( 'groups.getById', array( 'group_ids' => $name ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response[0]->gid; } //Является ли пользователь участником сообщества public function is_member($id) { $data = json_decode( $this->execute( 'groups.isMember', array( 'group_id' => $this->group_id, 'user_ids' => $id ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response; } //Бан юзера public function ban_user($id) { $data = json_decode( $this->execute( 'groups.banUser', array( 'group_id' => $this->group_id, 'user_id' => $id, 'end_date' => strtotime("+1month"), 'reason' => 1, 'comment' => 'Размещение записей в группе разрешено только участникам данной группы', 'comment_visible' => 1 ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response; } //Удаление записи со стены public function delete_post($id) { $data = json_decode( $this->execute( 'wall.delete', array( 'owner_id' => -$this->group_id, 'post_id' => $id ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response; } //постинг на стену public function post( $desc, $photo, $link ) { $data = json_decode( $this->execute( 'wall.post', array( 'owner_id' => -$this->group_id, 'from_group' => 1, 'message' => $desc, /* 'attachments' => $photo . ',' . $link */ 'attachments' => $photo ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response->post_id; return 0; } //загрузка фотографии public function upload_photo( $file ) { $data = json_decode( $this->execute( 'photos.getWallUploadServer', array( 'group_id' => $this->group_id ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } $ch = curl_init( $data->response->upload_url ); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data")); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt($ch, CURLOPT_POSTFIELDS, array('photo' => '@' . realpath($file))); $data = curl_exec($ch); curl_close($ch); $data = json_decode( $data ); if( isset( $data->error ) ) { return $this->error( $data ); } $data = json_decode( $this->execute( 'photos.saveWallPhoto', array( 'group_id' => $this->group_id, 'server' => $data->server, 'photo' => $data->photo, 'hash' => $data->hash ) ) ); if( isset( $data->error ) ) { return $this->error( $data ); } return $data->response['0']->id; } private function execute( $method, $params ) { $ch = curl_init( 'https://api.vk.com/method/' . $method . '?access_token=' . $this->token ); curl_setopt ( $ch, CURLOPT_HEADER, false ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params ); $data = curl_exec($ch); curl_close($ch); return $data; } private function error( $data ) { //обработка ошибок return false; } }
Код рабочий для php5. Я думая проблема в том, что в php 7 https://php.ru/manual/migration70.incompatible.html Удалена $HTTP_RAW_POST_DATA Вместо нее используйте поток php://input. А вот хз как правильно курлом передать картинку используя поток php://input. а может быть ошибка в json, тоже какие то изменения есть, т.к. отдает {"server":код сервера,"photo":"[]","hash":"хеш код"}