M
M
maksim_vasil4enk02016-11-23 16:43:08
PHP
maksim_vasil4enk0, 2016-11-23 16:43:08

How to properly upload photo api php?

Hi everybody. Help!
Loading in 3 steps
1st I get everything ok url, and 2nd

Step 2. Error code: 505. Error msg: one.image.server.upload.ContentUploadServerException: NO_IMAGE

How trouble did not turn the same
Kurl
function getUrl($url, $type = "GET", $params = array(), $timeout = 30, $image = false, $decode = true)
{
    if ($ch = curl_init())
    {
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);

        if ($type == "POST")
        {
            curl_setopt($ch, CURLOPT_POST, 1);

            // Картинка
            if ($image) {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            }
            // Обычный запрос       
            elseif($decode) {
                curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
            }
            // Текст
            else {
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
            }
        }

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
        
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

        $data = curl_exec($ch);

        curl_close($ch);

        // Еще разок, если API завис
        if (isset($data['error_code']) && $data['error_code'] == 5000) {
            $data = getUrl($url, $type, $params, $timeout, $image, $decode);
        }

        return $data;

    }
    else {
        return "{}";
    }
}

so send
// $p_imf = '/home/4655/bla.site.ua/ok/img/pic.jpg';
$params = array(
'pic1' => '@'.$p_imf,
);
// Отправляем картинку на сервер, подписывать не нужно
$step2 = json_decode( getUrl( $step1['upload_url'], "POST", $params, 30, true), true);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Medvedev, 2016-11-24
@rus89

Here is a similar problem for a person ru.stackoverflow.com/questions/491379/%D0%97%D0%B0...
In general, I recommend using the Guzzle Http Client, where the upload to the server is done like this .

R
Roman, 2017-04-10
@RomanTrakhtenberg

The line is commented out
// $p_imf = '/home/4655/bla.site.ua/ok/img/pic.jpg';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question