From 7d82d8b50005761e9e22e5162fc3d085bff492a9 Mon Sep 17 00:00:00 2001 From: edward Date: Thu, 21 Jan 2016 12:56:43 +0800 Subject: [PATCH] DataObjects/Images.php --- DataObjects/Images.php | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/DataObjects/Images.php b/DataObjects/Images.php index 05fa4730..7439ff74 100644 --- a/DataObjects/Images.php +++ b/DataObjects/Images.php @@ -709,4 +709,73 @@ class Pman_Core_DataObjects_Images extends DB_DataObject } + function createFromData($file, $filename=false) + { + // copy the file into the storage area.. + if (!file_exists($file) || !filesize($file)) { + return false; + } + + $filename = empty($filename) ? $file : $filename; + + if (empty($this->mimetype)) { + require_once 'File/MimeType.php'; + $y = new File_MimeType(); + $this->mimetype = $y->fromFilename($filename); + } + + $this->mimetype= strtolower($this->mimetype); + + if (array_shift(explode('/', $this->mimetype)) == 'image') { + + $imgs = @getimagesize($file); + + if (empty($imgs) || empty($imgs[0]) || empty($imgs[1])) { + // it's a file!!!! + } else { + 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; + + } + } -- 2.39.2