*/
function createFrom($file, $filename=false)
{
- print_r('createfrom');exit;
// copy the file into the storage area..
if (!file_exists($file) || !filesize($file)) {
return false;
function onUploadWithTbl($tbl, $fld)
{
- print_r('onUploadWithTbl');
if ( $tbl->__table == 'Images') {
return; // not upload to self...
}
/// ctrl not used??
function onUpload($roo)
{
- print_r('onUPload');
// echo $_FILES['imageUpload']['type'];exit;
if (empty($_FILES['imageUpload']['tmp_name']) ||
empty($_FILES['imageUpload']['name']) ||
if (!empty($mime_like)) {
$c->whereAdd("Images.mimetype LIKE '". $c->escape($mime_like) ."'");
}
+ $c->orderBy('created DESC');
return $c->fetchAll();
}
$fc = $this->toFileConvert();
// print_r($size);
// exit;
- $fc->convert($this->mimetype, $size);
+ $mt = $this->mimetype;
+ if (!preg_match('#^image/#i',$mt)) {
+ $mt = 'image/jpeg';
+ }
+ $fc->convert($mt, $size);
return $baseURL . $provider . "/$size/{$this->id}/{$this->filename}";
}
//$p->toEventString();
}
+ function onUploadFromData($data, $roo)
+ {
+ if (empty($data)) {
+ $this->err = "Missing file details";
+ return false;
+ }
+
+ if ($this->id) {
+ $this->beforeDelete();
+ }
+
+ if (empty($this->ontable)) {
+ $this->err = "Missing ontable";
+ return false;
+ }
+
+ if (!empty($this->imgtype) && $this->imgtype[0] == '-' && !empty($this->onid)) {
+ $img = DB_DataObject::factory('Images');
+ $img->onid = $this->onid;
+ $img->ontable = $this->ontable;
+ $img->imgtype = $this->imgtype;
+
+ $img->find();
+ while ($img->fetch()) {
+ $img->beforeDelete();
+ $img->delete();
+ }
+ }
+
+ require_once 'File/MimeType.php';
+ $y = new File_MimeType();
+
+ if (in_array($this->mimetype, array(
+ 'text/application',
+ 'application/octet-stream',
+ 'image/x-png', // WTF does this?
+ 'image/pjpeg', // WTF does this?
+ 'application/x-apple-msg-attachment', /// apple doing it's magic...
+ 'application/vnd.ms-excel', /// sometimes windows reports csv as excel???
+ 'application/csv-tab-delimited-table', // windows again!!?
+ ))) { // weird tyeps..
+ $inf = pathinfo($this->filename);
+ $this->mimetype = $y->fromExt($inf['extension']);
+ }
+
+ $ext = $y->toExt(trim((string) $this->mimetype ));
+
+ $this->filename = empty($this->filename) ?
+ ('gen-' . date('Y-m-d H:i:s') . '.' . $ext) : ($this->filename .'.'. $ext);
+
+ 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($file);
+
+ if (!empty($imgs) && !empty($imgs[0]) && !empty($imgs[1])) {
+ list($this->width , $this->height) = $imgs;
+ }
+ }
+
+// $this->filesize = filesize($file);
+ $this->created = date('Y-m-d H:i:s');
+
+
+ if (empty($this->filename)) {
+ $this->filename = basename($filename);
+ }
+
+ //DB_DataObject::debugLevel(1);
+ if (!$this->id) {
+ $this->insert();
+ } else {
+ $this->update();
+ }
+
+
+
+ $f = $this->getStoreName();
+ $dest = dirname($f);
+ if (!file_exists($dest)) {
+ // currently this is 0775 due to problems using shared hosing (FTP)
+ // it makes all the files unaccessable..
+ // you can normally solve this by giving the storedirectory better perms
+ // if needed on a dedicated server..
+ $oldumask = umask(0);
+ mkdir($dest, 0775, true);
+ umask($oldumask);
+ }
+
+ copy($file,$f);
+
+ // fill in details..
+
+ /* thumbnails */
+
+
+ // $this->createThumbnail(0,50);
+ return true;
+
+ }
+
}