function pieTempName($file) { $path = $GLOBALS['pie']['run_path'] . "/temp/" . pieEncodeName($file); if (@$GLOBALS['pie']['user']) { $path .= "." . $GLOBALS['pie']['user']; } return $path; }
function unlock($user) { // Expire existing locks: $file = $GLOBALS['pie']['run_path'] . '/lock'; if (!is_dir($file)) { return false; } if (!is_writable($file)) { return false; } if ($GLOBALS['pie']['edit_timeout']) { pieExpireDirectory($file, $GLOBALS['pie']['edit_timeout']); } // Remove lock file, if owner matches: $file = "{$file}/" . pieEncodeName($this->name); if (file_exists($file)) { list($current) = file($file); if (trim($current) != $user) { return false; } return unlink($file); } return false; }
// The upload is an update by the same user. // Delete the previous version before saving the new one. if (!$file->replace($name)) { pieError("FileWriteError"); } } } // Check for cached thumbnail images of former versions. if ($GLOBALS['pie']['image_caching']) { $cache = new Cache(); $cid = $cache->key('image', array('file' => $name)); if ($cache->exists($cid)) { $cache->delete($cid); } } else { $thumbnail = $GLOBALS['pie']['run_path'] . "/temp/_thumbnail_" . pieEncodeName($name); if (file_exists($thumbnail)) { unlink($thumbnail); } } // Prepare meta data of the file: $file->name = $name; $file->meta = array('stamp' => time(), 'author' => $GLOBALS['pie']['user']); // .. file size if ($_FILES['upload']['size']) { $file->meta['size'] = $_FILES['upload']['size']; } else { $file->meta['size'] = filesize(pieTempName("_upload")); } // .. file type if (preg_match('/^[a-z]+\\/[a-z]+[\\w\\-\\+\\.]*\\w+$/', $_FILES['upload']['type'])) {
function isValidName($name) { if (strlen(pieEncodeName($name)) > 253) { return false; } if ($GLOBALS['pie']['file_pattern']) { if (!pieCheckPattern($GLOBALS['pie']['file_pattern'], $name)) { return false; } } return true; }