Quick Start for PHP

  • Step 1. Add uploadcare-php to your composer.json:

    "require": {
        "uploadcare/uploadcare-php": ">=v1.1.0,<2.0"
    }
  • Step 2. Include the library.

    require_once 'vendor/autoload.php';
    use \Uploadcare;
  • Step 3. Create an instance of Uploadcare\Api:

    $api = new Uploadcare\Api('', '');
  • Step 4. To show a widget, add the following to your <head> tag and show an input where you want it:

    <head>
      <?php echo $api->widget->getScriptTag(); ?>
    </head>

    <form method="POST" action="upload.php">
      <?php echo $api->widget->getInputTag('qs-file'); ?>
      <input type="submit" value="Save!" />
    </form>
  • Step 5. When a file gets uploaded and your form is submitted, you will recieve a file_id among other $_POST parameters:

    $file_id = $_POST['qs-file'];
  • Step 6. $file_id is a file identifier. If you want to keep that file for more than 24-hour period, use the $file->store(); method to mark it as stored.

    $file = $api->getFile($file_id);
    $file->store();

    After that, save $file->getFileId(); in your database: it’s just a string containing a UUID.

  • Step 7. You can then use the $file object to display an image or otherwise interact with your file:

    <img src="<?php print $file->getUrl(); ?>" />
    <img src="<?php print $file->getUrl()->crop(300, 300, true)->effect('grayscale'); ?>" />

Read more in our uploadcare-php docs. In case of any questions, ask those around our community area or directly via email.

We’re always happy to help with code, integration, and other stuff. Search our site for more info or post your question in our Community Area.