PHP Classes

File: manuscript/Working with Pimf_Util_Uploaded.md

Recommend this page to a friend!
  Classes of Gjero Krsteski   PIMF   manuscript/Working with Pimf_Util_Uploaded.md   Download  
File: manuscript/Working with Pimf_Util_Uploaded.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PIMF
Framework for Web application development
Author: By
Last change: Update of manuscript/Working with Pimf_Util_Uploaded.md
Date: 5 months ago
Size: 805 bytes
 

Contents

Class file image Download

Uploaded files

Gives a methods to act in a secure way with a file/s uploaded through a form.

Create a file instance.

  $uploaded = new Pimf\Util\Uploaded(
    $_FILES['tmp_name'], $_FILES['name'],
    $_FILES['type'], $_FILES['size'], $_FILES['error']
  );

Create an instance using the factory-class for more security.

  $uploaded = Pimf\Util\Uploaded\Factory::get($_FILES);

Let Pimf\Util\Uploaded work for you.

  if ($uploaded instanceof Pimf\Util\Uploaded) {

    if(in_array(
        $upload->getClientMimeType(),
        array('image/gif', 'image/jpg'))
    ) {

      try {

        $uploaded->move(
          'path/to/your/images/dir', $upload->getClientOriginalName()
        );

      } catch (RuntimeException $e) {
        //error!!!
      }
    }
  }