Example #1
0
    $uploader->setCustomName($name);
    $uploader->sameName(true);
    $uploader->setUniqueFile();
    // Upload a file
    if (!($file = $api->uploadRepackFile('file', $uploader, $icon_path, $icon_path))) {
        $error = $api->getErrors();
        $response->status = 500;
        $response->message = $error[0];
        $response->json($response);
    }
    $file_name = strtok($file, '.');
    //var_dump($uploader,$icon_path,$icon_path_temp,$file_name);
    //return;
    if ($file) {
        $input = array('user_id' => $user->id, 'name' => Ut::toSlug($file_name), 'title' => $file_name, 'file' => $file, 'author' => trim($user->first_name . ' ' . $user->last_name), 'homepage' => $user->homepage, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"));
        if (!$model->iconCreate($input)) {
            $response->status = 500;
            $response->message = 'Unable to upload a icon set';
            $response->json($response);
        }
        $input['id'] = $db->inserId();
    }
    $response->data = $input;
    $response->json($response);
} elseif ($route->match('iconupdate', null)) {
    // Prepare and sanitize post input
    $_POST['updated_at'] = date("Y-m-d H:i:s");
    $api->setInputs($_POST, $model->getWhitelist('icons'));
    $skin = $model->iconFind(array('id' => $api->getInputVal('id'), 'user_id' => $user->id, 'name' => $api->getInputVal('name')));
    if (!$skin) {
        $response->status = 404;