• 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.

[Tutorial] Using the API to upload a file (PHP)

Deprecated
dep·re·cate [dep-ri-keyt]​
verb (used with object), dep·re·cat·ed, dep·re·cat·ing.
1. to express earnest disapproval of.
2. to urge reasons against; protest against (a scheme, purpose, etc.).
3. to depreciate; belittle.
4. Archaic. to pray for deliverance from.

Source: http://dictionary.reference.com/browse/deprecated


My point here is that you shouldn't call something deprecated when the current version is not production ready. Myself and two other friends of mine (who are also customers of yours) have seen in multiple instances that you've simply pushed Chevereto 3 prematurely which is something that all developers naturally do as their project nears the completion phase.

Like I said either in this thread or the other one, as a customer I am very excited about version 3 and even more now that I have installed a version of it on a VM to test out. I really like the hooks you placed for inserting custom CSS, banners ad placements, simply google analytics (and other external services such as alexa) integration, and most importantly to myself the ability to keep the image filenames in the URL (for SEO).

While I am very impressed with what you've done on Chevereto v3, it still has a few key issues to be resolved before I'd be comfortable with putting it into an actual production environment. I'm certain that you will be able to resolve these issues as you have already identified them here in this thread as well as in others, and my point really is that we feel that you really shouldn't be referring to Chevereto v2 as deprecated until these issues have reached a stable resolution.

In conclusion, I just want to stress that I'm not saying Chevereto v3 is poorly developed or anything along those lines. We just feel that at present you might want to slow down a bit with referring to Chevereto v2 as deprecated and pushing everyone to upgrade over to Chevereto v3....
 
You should use the term applied to software development, not the meaning from the dictionary. Otherwise "bug" will mean that there are actually insects or living things causing problems in a given software?. Deprecated means that the use of a given software or script should be avoided and that is not recommended to keep using it. In this case, is not recommended to keep developing over V2 because things will dramatically change when V3 introduces its API. Only when the API specification went public you will be safe to work in V2 API then merge to V3 because you will exactly know which things should change. V2 is also deprecated because is not longer being developed and because V3 has a complete new core.

Like I said, at the end is up to you. V2 is still a good product that it does the job and it doesn't have any issues but is not as good prepared to be extended and improved as V3. Label V2 as deprecated doesn't means that you must update to V3, this is not iTunes or something like that. But, since V3 script doesn't share anything with V2 there is no place for both codes, so the new code must be preferred. Also, licenses are lifetime so there isn't a money issue here is just push newer code.

Instead of keep asking on how I (or we) label a release we should be talking about how the V3 API will be, how the new things will be pushed, how the new update script will be, etc. Whine about how you miss something from V2 doesn't help me at all and it won't have any effect on actual development.

Want API for V3? Then lets talk about that. I've a lot of ideas and how to enable API even for your users but at the end code won't be there if we keep talking about old code.
 
Last edited:
Hello guys,

Today I will explain you how to upload a file using the Chevereto 2.0 API.
In fact, this is quite easy.

If you are a total newbie to php and html, I do not recommend to use the API.

First of all, you will need to create a .php file.

I named mine api.php
------------------------------------------------------------------------------------------------------------------------------------------------

So the first thing we need to do, is to create the html form.
This form is like any other upload form.
We call the current file, we set the method to post and because it is a file uploading form, we need to set the encryption type to multipart/form-data

Here is an example:
HTML:
<form action="api.php" method="post" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="submit" name="submit" />
</form>

------------------------------------------------------------------------------------------------------------------------------------------------
Next is the PHP code.

We must check if the form was submitted

PHP:
<?php
if (isset($_POST['submit']))
{
    //PHP code if the button named submit is pressed.
}
?>

Then since chevereto 2.0 api doesn't return any specific error code depending on the error, I decided to add a very basic validation of the file using the mime types.

We take the uploaded file ($_FILES['upload']) we retreive is type in the array and we compare using the in_array php function it to some values. In the eventuality that the file is invalid, we show and error message and we exit the application.

PHP:
    if (!in_array($_FILES['upload']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif')))
    {
        echo '<span style="color:#CC0000;">Not a valid file type, please upload PNG, JPG, JPEG or GIF images only.</span>';
        exit;
    }

Well, our api.php file is receiving a post request, but it most also send a post request to the api.

If you read carefully the documentation, you will see that you need your website url (if you are posting from a different website), your api key, the image base64_encoded and the return method.

so we will simply define theses with 1 value and 1 array.

You will see that I have "urlencode" my values, I don't think it is necessary, but it is preferable for security reasons.
** I'm not an expert in this domain, this is what I have read.

PHP:
    //Where is the api?
    $url = '[url]http://chevereto.com/2.0/api[/url]';

    // What do we send to chevereto api?
    $fields = array(
                        // The key, in this case my_api_key (the default one)
                        'key' => urlencode('my_api_key'),
                        // The image encoded in base64
                        'upload' => base64_encode(file_get_contents($_FILES['upload']['tmp_name'])),
                        // And how the api answer us?
                        'format' => urlencode('txt')
                    );

Now is the tricky part.
Since we are sending a post request, we must use CURL. Unfortunately, many web server unable it...
If this is the case on your server. You can also create the file without the form on the chevereto server, and instead simply create a html file on your second server. You will need to replace the action.
Instead of api.php you will have to write something like http://yourwebsite.com/api-call.php

Here is the CURL code, I won't explain everything because it is unnecessary.

PHP:
    //open connection
    $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);

    //close connection
    curl_close($ch);

and then we have a $result variable with the answer of the chevereto api.

------------------------------------------------------------------------------------------------------------------------------------------------

You can play with the result now.

You can redirect using
PHP:
header('location '.$result);

or simply print it.
PHP:
print($result);

some useful php methods depending of the api callback:

XML : Simple XML

JSON : JSON decode

------------------------------------------------------------------------------------------------------------------------------------------------

If you have any questions, do not hesitate to post!


Download this tutorial


Download link this tutorial is off :/
 
Back
Top