Beispiel #1
0
 /**
  * Constructor.
  *
  * @param string $stored_filename The stored name of the file.
  * @param string $orig_filename The original name of the file.
  */
 public function __construct($stored_filename, $orig_filename = '')
 {
     if (\pdyn\datatype\Validator::filename($stored_filename) !== true) {
         throw new \Exception('Invalid filename received', 400);
     }
     if (!empty($orig_filename) && !is_scalar($orig_filename)) {
         throw new \Exception('Uploaded file orig filename must be scalar or empty', 400);
     }
     $this->stored_filename = \pdyn\filesystem\FilesystemUtils::sanitize_filename($stored_filename);
     $this->orig_filename = \pdyn\filesystem\FilesystemUtils::sanitize_filename($orig_filename);
 }
Beispiel #2
0
 /**
  * Test validate filename.
  */
 public function test_validate_filename()
 {
     $invalid = array(true, false, null, array(), new \stdClass(), '../test', '/etc/passwd');
     foreach ($invalid as $val) {
         $this->assertEquals(false, \pdyn\datatype\Validator::filename($val));
     }
     $valid = array('test', 'test.txt', '1');
     foreach ($valid as $val) {
         $this->assertEquals(true, \pdyn\datatype\Validator::filename($val));
     }
 }
Beispiel #3
0
 /**
  * Get image EXIF information.
  *
  * @return array Array of EXIF data.
  */
 public function get_exif()
 {
     $return = [];
     set_error_handler(function () {
     });
     try {
         if (extension_loaded('exif') && $this->mime === 'image/jpeg') {
             $exif = exif_read_data($this->filename);
             $return = array_merge($exif, $return);
             if (isset($exif['Orientation']) && in_array($exif['Orientation'], [1, 2, 3, 4, 5, 6, 7, 8])) {
                 $return['orientation'] = (int) $exif['Orientation'];
             }
             if (isset($exif['FileDateTime']) && \pdyn\datatype\Validator::timestamp($exif['FileDateTime']) === true) {
                 $return['timestamp'] = (int) $exif['FileDateTime'];
             }
             if (!empty($exif['FileName']) && \pdyn\datatype\Validator::filename($exif['FileName']) === true) {
                 $return['filename'] = (string) $exif['FileName'];
             }
         }
     } catch (\Exception $e) {
         $return = [];
     }
     restore_error_handler();
     return $return;
 }