Exemplo n.º 1
0
 /**
  * Image rotate
  * @param $group
  * @param bool $multi
  */
 protected function image_rotate($group, $multi = true)
 {
     $id = $this->request->param('param');
     if ($multi) {
         $fu = new Fileuploaders($group, $this->user->id, $id);
     } else {
         $fu = new Fileuploader($group, $this->user->id, $id);
     }
     if ($src = $fu->image_rotate()) {
         $this->json['src'] = $src;
         $this->json['success'] = true;
         $this->json['message'] = __('settings.image_rotated');
     } else {
         $this->json['message'] = __('settings.image_error_rotating');
     }
 }
            
            if ( false === $ext ) {
                throw new RuntimeException('Invalid file format.');
            }
            */
            /* Alternative to getting file extention */
            $name = $_FILES[$fileName]["name"];
            $ext = strtolower(end(explode(".", $name)));
            if (preg_match("/^(jpeg|jpg|png|gif)\$/", $ext) == false) {
                throw new RuntimeException('Invalid file format.');
            }
            /* Alternative END */
            // You should name it uniquely.
            // DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !!
            // On this example, obtain safe unique name from its binary data.
            $fileNameSha1 = sha1_file($_FILES[$fileName]['tmp_name']);
            $location = sprintf('./uploads/%s.%s', $fileNameSha1, $ext);
            if (!move_uploaded_file($_FILES[$fileName]['tmp_name'], $location)) {
                throw new RuntimeException('Failed to move uploaded file.');
            }
            echo 'File is uploaded successfully.';
        } catch (RuntimeException $e) {
            echo $e->getMessage();
        }
    }
}
$f = new Fileuploader();
$f->uploadFile($_FILES[$fileName]);
?>
  </body>
</html>