+ function createFromData($data)
+ {
+
+ $this->mimetype= strtolower($this->mimetype);
+
+ if (array_shift(explode('/', $this->mimetype)) == 'image') {
+
+ $imgs = @getimagesize($data);
+
+ if (!empty($imgs) && !empty($imgs[0]) && !empty($imgs[1])) {
+ list($this->width , $this->height) = $imgs;
+ }
+ }
+
+ $this->created = date('Y-m-d H:i:s');
+
+ if (!$this->id) {
+ $this->insert();
+ } else {
+ $this->update();
+ }
+
+ $f = $this->getStoreName();
+ $dest = dirname($f);
+ if (!file_exists($dest)) {
+ $oldumask = umask(0);
+ mkdir($dest, 0775, true);
+ umask($oldumask);
+ }
+
+ file_put_contents($f, file_get_contents("data://" . $data));
+
+ $o = clone($this);
+
+ $this->filesize = filesize($f);
+
+ $this->update($o);
+
+ return true;
+
+ }
+