Exemplo n.º 1
0
     $response->message = 'The skin with the name ' . $name . ' already exists! Please rename your skin and try it to upload again.';
     $response->json($response);
 }
 $skin_path = 'storage/skins/';
 $skin_path_temp = 'storage/skins/temp/';
 $uploader = new Uploader();
 $uploader->setDir($skin_path);
 $uploader->setExtensions(array('gz', 'zip'));
 //allowed extensions list//
 $uploader->setMaxSize(0.5);
 //set max file size to be allowed in MB//
 $uploader->setCustomName($name);
 $uploader->sameName(true);
 $uploader->setUniqueFile();
 // Upload a file
 if (!($file = $api->uploadSkin($uploader, $skin_path, $skin_path_temp))) {
     $error = $api->getErrors();
     $response->status = 500;
     $response->message = $error[0];
     $response->json($response);
 }
 $file_name = strtok($file, '.');
 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->skinCreate($input)) {
         $response->status = 500;
         $response->message = 'Unable to upload a skin';
         $response->json($response);
     }
     $input['id'] = $db->inserId();
 }