PHP SDK Image Reference

upload ($fileRoute, $options)

Returns: Object

Method used to upload image to the specified location on disk.

Parameters:


  • $fileRoute

    The path relative to the $_SERVER['DOCUMENT_ROOT'] global variable were the image should be uploaded.

    Type: String

  • $options

    This parameter is optional. It can be used to pass custom options for the image upload.

    Type: Array


$options parameter:

  • fieldname

    The field name from the $_FILES global variable.

    Type: String
    Default:
    "file"
  • validation

    An array or a function used to validate the uploaded image. The array specifies the allowed image extensions through allowedExts and the allowed mime types through allowedMimeTypes. The function should be invoked with: filePath, and mimetype.

    Type: Array or Function
    Default:
    array(
      'allowedExts' => array('gif', 'jpeg', 'jpg', 'png', 'svg', 'blob'),
      'allowedMimeTypes' => array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml')
    )
    
  • resize

    An array with custom options to scale the image. Available options are the ones from Imagick::resizeImage. Example:

    array(
      'columns' => 200,
      'rows' => 200,
      'filter' => imagick::FILTER_LANCZOS,
      'blur' => 1,
      'bestfit' => TRUE
    )

    Type: Array
    Default:
    NULL

Response

If the upload is completed successfully, the method returns an object with the absolute path to the uploaded image. If an error occurs, the method returns an error.

try {
  $response = FroalaEditor_Image::upload('/uploads/');
  echo stripslashes(json_encode($response));
}
catch (Exception $e) {
  http_response_code(404);
}

delete ($src)

Returns: Boolean

Method used to delete an image from disk.

Parameters:


  • $src

    The path relative to the $_SERVER['DOCUMENT_ROOT'] global variable to the image that should be deleted.

    Type: String

list ($folderPath, $thumbPath)

Returns: Array

Method used to list all images from disk.

Parameters:


  • $folderPath

    The path relative to the $_SERVER['DOCUMENT_ROOT'] global variable from where the images are being loaded.

    Type: String

  • $thumbPath

    The path relative to the $_SERVER['DOCUMENT_ROOT'] global variable from where the image thumbs are being loaded.

    Type: String

Response

If the request is completed successfully, the method returns an array with images. If an error occurs, the method returns an error.

try {
  $response = FroalaEditor_Image::list('/uploads/');
  echo stripslashes(json_encode($response));
}
catch (Exception $e) {
  http_response_code(404);
}