DataObjects/Images.php
[Pman.Core] / DataObjects / Images.php
index 15c01a7..87688cf 100644 (file)
@@ -658,19 +658,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             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();
         
@@ -690,67 +677,54 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         $ext = $y->toExt(trim((string) $this->mimetype ));
         
         $this->filename = empty($this->filename) ? 
-            ('gen-' . date('Y-m-d H:i:s') . '.' . $ext) : ($this->filename .'.'. $ext); 
+            ('image-upload-' . 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);
+            $imgs = @getimagesize($data);
             
-            if (empty($imgs) || empty($imgs[0]) || empty($imgs[1])) {
-                // it's a file!!!!
-            } else {
+            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);
+        file_put_contents($f, file_get_contents("data://" . $data));
         
-        // fill in details..
+        $o = clone($this);
         
-        /* thumbnails */
+        $this->filesize = filesize($f);
+        
+        $this->update($o);
         
-     
-       // $this->createThumbnail(0,50);
         return true;
         
     }