// allow create / edit / if the user has
if (!$au) {
-
-
-
return false;
}
//$p->toEventString();
}
- function onUploadFromData($filename, $data, $roo)
+ function onUploadFromData($data, $roo)
{
-// echo $_FILES['imageUpload']['type'];exit;
- if (empty($_FILES['imageUpload']['tmp_name']) ||
- empty($_FILES['imageUpload']['name']) ||
- empty($_FILES['imageUpload']['type'])
- ) {
+ if (empty($data)) {
$this->err = "Missing file details";
return false;
}
if ($this->id) {
$this->beforeDelete();
}
- if ( empty($this->ontable)) {
+
+ if (empty($this->ontable)) {
$this->err = "Missing ontable";
return false;
}
}
-
-
require_once 'File/MimeType.php';
$y = new File_MimeType();
- $this->mimetype = $_FILES['imageUpload']['type'];
+
if (in_array($this->mimetype, array(
'text/application',
'application/octet-stream',
'application/vnd.ms-excel', /// sometimes windows reports csv as excel???
'application/csv-tab-delimited-table', // windows again!!?
))) { // weird tyeps..
- $inf = pathinfo($_FILES['imageUpload']['name']);
+ $inf = pathinfo($this->filename);
$this->mimetype = $y->fromExt($inf['extension']);
}
-
$ext = $y->toExt(trim((string) $this->mimetype ));
- $this->filename = empty($this->filename) ?
- $_FILES['imageUpload']['name'] : ($this->filename .'.'. $ext);
-
-
+ if(array_pop(explode('.', $this->filename)) != $ext){
+ $this->filename = $this->filename .'.'. $ext;
+ }
- if (!$this->createFrom($_FILES['imageUpload']['tmp_name'])) {
+ if (!$this->createFromData($data)) {
return false;
}
+
return true;
}
+ 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;
+
+ }
+
}