/** * Constructor. * @param {array} $files Uploaded file(s). */ public function __construct($files) { $numItems = count($files['tmp_name']); for ($i = 0; $i < $numItems; $i++) { $error = $files['error'][$i]; // File input in form for which no file has been selected if ($error == UPLOAD_ERR_NO_FILE) { continue; } // Something actually went wrong with an upload if ($error != UPLOAD_ERR_OK) { $msg = sprintf('[%s] Upload error for file <code>%s</code>: %s', get_class(), htmlspecialchars($files['name'][$i]), self::getUploadErrorString($error)); ae_Log::error($msg); $json = str_replace('\\/', '/', json_encode($files)); ae_Log::debug('File ' . $i . ': ' . $json); continue; } $type = self::getMIMEType($files['tmp_name'][$i], $files['type'][$i]); $m = new ae_MediaModel(); $m->setName($files['name'][$i]); $m->setTmpName($files['tmp_name'][$i]); $m->setDatetime(date('Y-m-d H:i:s')); $m->setType($type); $m->setUserId(ae_Security::getCurrentUserId()); $m->setStatus(ae_MediaModel::STATUS_AVAILABLE); $m->setMetaInfo(self::getMetaInfo($m)); $this->items[] = $m; } }
public function testSetMetaInfo() { $m = new ae_MediaModel(); $m->setMetaInfo('{"file_size":400,"hocus":"pocus"}'); $this->assertEquals($m->getMetaInfo(), array('file_size' => 400, 'hocus' => 'pocus')); $m->setMetaInfo(array('key' => 'value', 'lorem' => 2, 'bool' => FALSE)); $this->assertEquals($m->getMetaInfo(), array('key' => 'value', 'lorem' => 2, 'bool' => FALSE)); $this->setExpectedException('Exception'); $m->setMetaInfo('bogus'); }