Example #1
0
$name = pieBeautifyName($name);
if (!is_uploaded_file($_FILES['upload']['tmp_name'])) {
    pieError("UploadError");
}
if (!move_uploaded_file($_FILES['upload']['tmp_name'], pieTempName("_upload"))) {
    pieError("FileWriteError");
}
if ($file->exists($name)) {
    // A file with the name already exists.
    if (!$file->read($name, 0)) {
        pieError("FileReadError");
    }
    if ($file->meta['author'] == $GLOBALS['pie']['user'] && !@$_REQUEST['append']) {
        // 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);