trigger_error('can\'t create upload directory: ' . $filename, E_USER_ERROR);
}
}
- $filename .= $this->forlife . '-' . $this->category;
+ $filename .= $this->forlife . '--' . $this->category;
if ($file_id) {
- $filename .= '-' . $file_id;
+ $filename .= '--' . $file_id;
}
return $filename;
}
} else if (!move_uploaded_file($file['tmp_name'], $this->filename)) {
return false;
}
- $this->checkContentType();
+ $this->checkContentType();
return true;
}
public function download($url)
{
+ if (!$url || @parse_url($url) === false) {
+ trigger_error('malformed URL given', E_USER_NOTICE);
+ return false;
+ }
$data = file_get_contents($url);
if (!$data) {
return false;
public function rm()
{
@unlink($this->filename);
- clearstatcache();
+ @clearstatcache();
}
public function rename($fn)
return file_exists($this->filename);
}
- static public function listFiles($forlife = '*', $category = '*', $basename = false)
+ static public function listRawFiles($forlife = '*', $category = '*', $uniq = false, $basename = false)
{
global $globals;
$filename = $globals->spoolroot . '/spool/uploads/temp/';
- $filename .= $forlife . '-' . $category;
+ $filename .= $forlife . '--' . $category;
+ if (!$uniq) {
+ $filename .= '--*';
+ }
$files = glob($filename);
if ($basename) {
- array_walk($files, 'basename');
+ $files = array_map('basename', $files);
}
return $files;
}
- static public function clear($user = '*', $category = '*')
+ static public function listFilenames($forlife = '*', $category = '*')
+ {
+ $files = PlUpload::listRawFiles($forlife, $category, false, true);
+ foreach ($files as &$name) {
+ list($forlife, $cat, $fn) = explode('--', $name, 3);
+ $name = $fn;
+ }
+ return $files;
+ }
+
+ static public function &listFiles($forlife = '*', $category = '*', $uniq = false)
+ {
+ $res = array();
+ $files = PlUpload::listRawFiles($forlife, $category, $uniq, true);
+ foreach ($files as $name) {
+ list($forlife, $cat, $fn) = explode('--', $name, 3);
+ $res[$fn] = new PlUpload($forlife, $cat, $fn);
+ }
+ return $res;
+ }
+
+ static public function clear($user = '*', $category = '*', $uniq = false)
{
- $files = PlUpload::listFiles($user, $category, false);
- array_walk($files, 'unlink');
+ $files = PlUpload::listRawFiles($user, $category, $uniq, false);
+ array_map('unlink', $files);
}
public function contentType()
return $this->type;
}
+ public function isType($type, $subtype = null)
+ {
+ list($mytype, $mysubtype) = explode('/', $this->type);
+ if ($mytype != $type || ($subtype && $mysubtype != $subtype)) {
+ return false;
+ }
+ return true;
+ }
+
public function imageInfo()
{
- return getimagesize($this->filename);
+ static $map;
+ if (!isset($map)) {
+ $tmpmap = array (IMG_GIF => 'gif', IMG_JPG => 'jpeg', IMG_PNG => 'png', IMG_WBMP => 'bmp', IMG_XPM => 'xpm');
+ $map = array();
+ $supported = imagetypes();
+ foreach ($tmpmap as $type=>$mime) {
+ if ($supported & $type) {
+ $map[$type] = $mime;
+ }
+ }
+ }
+ $array = getimagesize($this->filename);
+ $array[2] = @$map[$array[2]];
+ if (!$array[2]) {
+ trigger_error('unknown image type', E_USER_NOTICE);
+ return null;
+ }
+ return $array;
}
public function resizeImage($max_x = -1, $max_y = -1, $min_x = 0, $min_y = 0, $maxsize = -1)
return false;
}
$image_infos = $this->imageInfo();
- if (empty($image_infos)) {
+ if (!$image_infos) {
trigger_error('invalid image', E_USER_NOTICE);
return false;
}
list($this->x, $this->y, $mimetype) = $image_infos;
- if ($mimetype < 1 || $mimetype > 3) { // 1 - gif, 2 - jpeg, 3 - png
- trigger_error('unknown image type', E_USER_NOTICE);
- return false;
- }
if ($max_x == -1) {
$max_x = $this->x;
}