• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Uploading through API

Smilley

Chevereto Member
Hello, I have a problem uploading an image through api. Here's how I'm trying to use it:

Upload form with uploadfive.js http://img.smilley.ru/index2.php:
HTML:
            <form role="form">
                <div class="form-group">
                <label for="exampleInputFile">Выберите файлы</label>
                <input type="file" multiple="true" id="exampleInputFile">
                <p class="help-block">Example block-level help text here.</p>
              </div>
              <button type="submit" class="btn btn-default">Submit</button>
            </form>
JS code for that form:
Code:
$(function() {
    $('#exampleInputFile').uploadifive({
        'uploadScript' : 'test.php',
        'onUploadFile' : function(file) {
            alert(file.name + 'is being uploaded.');
        },
        'onUploadComplete' : function(file, data) {
            alert('The file ' + file.name + ' uploaded successfully. Data:'+data);
        },
        'removeCompleted' : true
    });
});

test.php:
PHP:
<?php
error_reporting(E_ALL);
    $url = '[url]http://img.smilley.ru/api[/url]';
    // What do we send to chevereto api?
    $fields = array(
                        // The key, in this case my_api_key (the default one)
                        'key' => urlencode('api'),
                        // The image encoded in base64
                        'upload' => base64_encode(file_get_contents($_FILES['Filedata']['tmp_name'])),
                        // And how the api answer us?
                        'format' => urlencode('txt')
                    );

        //open connection
    $ch = curl_init();

    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, sizeof($fields));
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 240);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

    //execute post
    $result = curl_exec($ch);
    echo $result;
    //close connection
    curl_close($ch);

    #echo file_get_contents($_FILES['Filedata']['tmp_name']);


?>

But it fails to upload anything. Any ideas please?

Best regards,
Vladislav.
 
There are several errors in your PHP code. Things like you are calling twice the curl handle, your url is inside a bbcode bracket (why?) and you have disabled error reporting (always enable this when testing).
 
WOW! It was that easy, now it works, thanks a lot!

1) Doesn't error_reporting(E_ALL); reports all errors?
2) bbcode transfered from copy-paste from API tutorial, was wondering what it's doing in the code, but didn't try removing it.

Added:

How do I change badge to "Solved"?
 
Back
Top