/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function checkPerm($perm, $au)
+ function checkPerm($lvl, $au)
{
// default permissons are to
// allow create / edit / if the user has
if (!$au) {
-
-
-
return false;
}
$o = $this->object();
//print_r($o);
- if (method_exists($o, 'hasPerm')) {
+ if (method_exists($o, 'checkPerm')) {
// edit permissions on related object needed...
- return $o->hasPerm( $perm == 'S' ? 'S' : 'E' , $au);
+ return $o->checkPerm( $lvl == 'S' ? 'S' : 'E' , $au);
}
/// ctrl not used??
function onUpload($roo)
{
-// echo $_FILES['imageUpload']['type'];exit;
+ //print_r($_FILES); echo $_FILES['imageUpload']['type'];exit;
if (empty($_FILES['imageUpload']['tmp_name']) ||
empty($_FILES['imageUpload']['name']) ||
empty($_FILES['imageUpload']['type'])
$ff->Pman_Images['public_baseURL'] : $ff->baseURL;
if (!empty($req['query']['imagesize'])) {
- $baseURL = isset($req['query']['imageBaseURL']) ? $req['query']['imageBaseURL'] : false;
+ // query/imageBaseURL ... depricated...? -- set it in config?
+
+ $baseURL = isset($req['query']['imageBaseURL']) ? $req['query']['imageBaseURL'] : $ret['public_baseURL'];
$ret['url'] = $this->URL(-1, '/Images/Download',$baseURL);
//$p->toEventString();
}
- function onUploadFromData($filename, $filetype, $data, $roo)
+ function onUploadFromData($data, $roo)
{
- if (empty($filename) || empty($filetype) || empty($data)) {
+ if (empty($data)) {
$this->err = "Missing file details";
return false;
}
}
if (!empty($this->imgtype) && $this->imgtype[0] == '-' && !empty($this->onid)) {
+ // then its an upload
$img = DB_DataObject::factory('Images');
$img->onid = $this->onid;
$img->ontable = $this->ontable;
$img->beforeDelete();
$img->delete();
}
+
}
require_once 'File/MimeType.php';
$y = new File_MimeType();
- $this->mimetype = $filetype;
+
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($filename);
+ $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($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);
- }
+ 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);
}
+ print_R(file_get_contents($data));exit;
+ file_put_contents($f, file_get_contents("data://" . $data));
- copy($file,$f);
+ $o = clone($this);
- // fill in details..
+ $this->filesize = filesize($f);
- /* thumbnails */
+ $this->update($o);
-
- // $this->createThumbnail(0,50);
return true;
}