コード例 #1
0
ファイル: ae_FileUpload.php プロジェクト: sebadorn/aestas3
 /**
  * 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;
     }
 }
コード例 #2
0
ファイル: create.php プロジェクト: sebadorn/aestas3
/**
 * Update media.
 * @return {int} ID of the media object.
 */
function updateMedia()
{
    if (!isset($_POST['media-name']) || $_POST['media-name'] == '') {
        header('Location: ../admin.php?error=missing_data_for_media');
        exit;
    }
    $media = new ae_MediaModel();
    $media->load($_POST['edit-id']);
    $media->setMediaPath('../../media/');
    $media->setName($_POST['media-name']);
    if (!$media->save()) {
        return FALSE;
    }
    return $media->getId();
}
コード例 #3
0
 public function testSetName()
 {
     $m = new ae_MediaModel();
     $m->setName('my comment filter');
     $this->assertEquals($m->getName(), 'my comment filter');
     $m->setName(4);
     $this->assertTrue($m->getName() === '4');
     $m->setName('should/not/be/a/path.png');
     $this->assertEquals($m->getName(), 'should-not-be-a-path.png');
     $m->setName('should\\not\\be\\a\\path.png');
     $this->assertEquals($m->getName(), 'should-not-be-a-path.png');
     $this->setExpectedException('Exception');
     $m->setName('');
 }