Beispiel #1
0
 function fetchImage($url)
 {
     $this->log("FETCH : {$url}\n");
     if ($url[0] == '/') {
         $ff = HTML_FlexyFramework::get();
         $file = $ff->rootDir . $url;
         require_once 'File/MimeType.php';
         $m = new File_MimeType();
         $mt = $m->fromFilename($file);
         $ext = $m->toExt($mt);
         return array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($file), 'file' => $file);
     }
     //print_R($url); exit;
     if (preg_match('#^file:///#', $url)) {
         $file = preg_replace('#^file://#', '', $url);
         require_once 'File/MimeType.php';
         $m = new File_MimeType();
         $mt = $m->fromFilename($file);
         $ext = $m->toExt($mt);
         return array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($file), 'file' => $file);
     }
     // CACHE???
     // 2 files --- the info file.. and the actual file...
     // add user
     // unix only...
     $uinfo = posix_getpwuid(posix_getuid());
     $user = $uinfo['name'];
     $cache = ini_get('session.save_path') . "/Pman_Core_Mailer-{$user}/" . md5($url);
     if ($this->cache_images && file_exists($cache) && filemtime($cache) > strtotime('NOW - 1 WEEK')) {
         $ret = json_decode(file_get_contents($cache), true);
         $this->log("fetched from cache");
         $ret['file'] = $cache . '.data';
         return $ret;
     }
     if (!file_exists(dirname($cache))) {
         mkdir(dirname($cache), 0700, true);
     }
     require_once 'HTTP/Request.php';
     $a = new HTTP_Request($this->mapurl($url));
     $a->sendRequest();
     $data = $a->getResponseBody();
     $this->log("got file of size " . strlen($data));
     $this->log("save contentid " . md5($url));
     file_put_contents($cache . '.data', $data);
     $mt = $a->getResponseHeader('Content-Type');
     require_once 'File/MimeType.php';
     $m = new File_MimeType();
     $ext = $m->toExt($mt);
     $ret = array('mimetype' => $mt, 'ext' => $ext, 'contentid' => md5($url));
     file_put_contents($cache, json_encode($ret));
     $ret['file'] = $cache . '.data';
     return $ret;
 }
Beispiel #2
0
 /**
  * create an email from file.
  * these must have been set first.
  * ontable / onid.
  * 
  */
 function createFrom($file, $filename = false)
 {
     // copy the file into the storage area..
     if (!file_exists($file) || !filesize($file)) {
         $this->err = "File {$file} did not exist or is 0 size";
         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;
 }