if (is_file($oldFile) && file_exists($oldFile)) {
                    unlink($oldFile);
                }
                # delete the thumbnail images if any
                if (is_array($dimensions) && count($dimensions)) {
                    foreach ($dimensions as $d) {
                        $thumbFile = $uploadDir . $d . _DS_ . $post[$name];
                        if (is_file($thumbFile) && file_exists($thumbFile)) {
                            unlink($thumbFile);
                        }
                    }
                }
            }
        } else {
            $error = $file->getError();
            validation_addError($name, $error['message']);
        }
    }
    if (count(validation_get('errors'))) {
        $errors = validation_get('errors');
        # if there is any validation error and if there was any uploaded file
        $data['error'] = array('id' => $errors[0]['htmlID'], 'plain' => $errors[0]['msg'], 'html' => _msg($errors, 'error', 'html'));
        $data['value'] = $post[$name];
    }
    if (!$data['savedId'] && isset($post[$name . '-id']) && $post[$name . '-id']) {
        # if there was any saved data in db
        $data['savedId'] = $post[$name . '-id'];
    }
}
?>
<!DOCTYPE html>
Esempio n. 2
0
        $args = array();
        $user = db_select('user', 'u')->where()->condition('LOWER(username)', strtolower($txtUsername))->getSingleResult();
        if ($user) {
            if ($user->username === 'admin' && $user->isMaster || $user->password && $user->password == _encrypt($txtPwd)) {
                $success = true;
                unset($user->password);
                # Create the Authentication object
                auth_create($user->uid, $user);
            } else {
                # Other follow-up errors checkup (if any)
                validation_addError('Password', _t('Password does not match.'));
                $error = true;
            }
        } else {
            # Other follow-up errors checkup (if any)
            validation_addError('Username', 'Username does not exists.');
            $error = true;
        }
        if ($error) {
            form_set('error', validation_get('errors'));
        }
        if ($success) {
            form_set('success', true);
            form_set('redirect', _url('admin/post'));
        }
    } else {
        form_set('error', validation_get('errors'));
    }
}
form_respond('frmLogin');
# Ajax response
Esempio n. 3
0
        $file->set('resizeMode', FILE_RESIZE_BOTH);
        // (optional) this overrides the global setting `$lc_imageFilterSet['resizeMode']`
        $file->set('maxDimension', '800x600');
        // (optional) this overrides the global setting `$lc_imageFilterSet['maxDimension']`
        $file->set('jpgQuality', 75);
        // (optional) this overrides the global setting `$lc_imageFilterSet['jpgQuality']`
        $uploads = $file->upload('filImage');
        // argument could be $_FILES['filImage'] or 'filImage'
        if ($uploads) {
            $success = true;
            # this should be set to true only when db operation is successful.
            if ($success) {
                form_set('success', true);
                $flashMsg = array();
                $flashMsg[] = _t('File has been uploaded.');
                $flashMsg[] = 'name: ' . $uploads['name'];
                $flashMsg[] = 'fileName: ' . $uploads['fileName'];
                $flashMsg[] = 'originalFileName: ' . $uploads['originalFileName'];
                $flashMsg[] = 'extension: ' . $uploads['extension'];
                flash_set($flashMsg, 'file-upload-success');
                _redirect();
            }
        } else {
            $error = $file->getError();
            validation_addError('filImage', $error['message']);
            form_set('error', validation_get('errors'));
        }
    } else {
        form_set('error', validation_get('errors'));
    }
}