R
R
rusgayfer2017-05-31 17:22:35
PHP
rusgayfer, 2017-05-31 17:22:35

API VK error output how to do?

How to display the text "Minimum image resolution is 1280x1024px"? If I upload an image with a smaller size, an error occurs.
This is not correct:

if (isset($membeer['response']['error'])) {
                   $message = "<div class=\"callout callout-danger\">Минимальное разрешение изображения 1280x1024px</div>";
                   $_SESSION['token'] = $token;  }

if (isset($_POST['reload']) && $_POST['reload'] !== '') {
    if (isset($rowCount2) == isset($groupId[1])) {
    $allowFiles = ['jpg', 'png', 'gif', 'bmp', 'jpeg'];
    $attachments = '';  
    $account['token'] = 'тут токен';
    $group['albumfon'] = 244929031;
    $token = $account['token'];
     $attachforpost = '';
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
        $ext = pathinfo($_FILES['file']['name']);
        if(!isset($ext['extension'])) { $ext['extension'] = '';}
        $ext = strtolower($ext['extension']);
            if (!in_array($ext, $allowFiles)) {
                $message = "<div class=\"callout callout-danger\">Ошибка при загрузке файла: загрузить можно только файлы с расширением jpg, png, gif, bmp, jpeg. </div>";} 
            elseif(!is_uploaded_file($_FILES["file"]["tmp_name"]) || !move_uploaded_file($_FILES["file"]["tmp_name"], "/tmp/{$token}_".$_FILES["file"]["name"])) {
                $message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: попробуйте еще раз. </div>";$_SESSION['token'] = $token; } 
            else {
            $members = json_decode(file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$group['albumfon']}&group_id=79668981&access_token={$account['token']}"),true);
           //var_dump($members);
                if (isset($members['response']['error'])) {
                $message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: Сервис недоступен, попробуйте повторить позднее. </div>"; 
                $_SESSION['token'] = $token;
                } else {  
                    $curl = curl_init($members['response']['upload_url']);
                    $opts = [
                      CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
                      CURLOPT_RETURNTRANSFER => true,
                      CURLOPT_SSL_VERIFYPEER => false,
                      CURLOPT_SSL_VERIFYHOST => false,
                      CURLOPT_POSTFIELDS => [
            'file1' => new CURLFile("/tmp/{$token}_".$_FILES["file"]["name"])
                      ]
                    ]; 
                    curl_setopt_array($curl, $opts);
                    $photoRequest = json_decode(curl_exec($curl), true); 
                    $membeer = json_decode(file_get_contents("https://api.vk.com/method/photos.save?server={$photoRequest['server']}&photos_list={$photoRequest['photos_list']}&album_id={$group['albumfon']}&group_id=79668981&hash={$photoRequest['hash']}&access_token={$account['token']}"),true);
                   	//var_dump($membeer);	
                    if (isset($request['response']['error'])) {
                    $message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: Сервис недоступен, попробуйте повторить позднее. </div>";
                    $_SESSION['token'] = $token; }
          else { $attachforpost = $membeer['response'][0]["src_xxbig"];}
          if (isset($membeer['response']['error'])) {
                   $message = "<div class=\"callout callout-danger\">Минимальное разрешение изображения 1280x1024px</div>";
                   $_SESSION['token'] = $token;  }
                }
            }
    }
}
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-05-31
@webinar

API VK error output how to do?

So she comes out. Do you need something different? Look towards php.net/exceptions

R
rusgayfer, 2017-06-10
@rusgayfer

Please help me to implement I don't understand how

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question