Working with Pimf_Util_Uploaded

g.krsteski edited this page Jun 3, 2014 · 6 revisions

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!!!
      }
    }
  }
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.