Advertisement
NFL

Fuuuucking ass...

NFL
May 2nd, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 KB | None | 0 0
  1. <?php
  2.  
  3. require_once ('../includes/functions.php');
  4. $task = (isset($_GET['task']) ? $_GET['task'] : 'default');
  5. switch ($task) {
  6.     case 'add':
  7.         if (empty($_POST)) {
  8.             include_once 'forms/adddata.php';
  9.         } else {
  10.             $name = $_POST['name'];
  11.             $shortDescription = $_POST['short_rescription'];
  12.             $fullDescription = $_POST['full_description'];
  13.             $created = date("Y-m-d H:i:s");
  14.             $createdBy = (int) $_SESSION['id'];
  15.             if (mysql_query("INSERT INTO data(name, full_description, short_description, created, created_by)
  16.                VALUES('$name', '$fullDescription', '$shortDescription', '$created', '$createdBy')")) {
  17.                 $dataId = mysql_insert_id();
  18.                 $query = '';
  19.                 $query.="INSERT INTO data_category(data_id, subcat_id, maincat_id) VALUES ";
  20.                 foreach ($_POST['subcat_id'] as $subcatId) {
  21.                     $mainCatId = getMainCatId($subcatId);
  22.                     $query.="('$dataId', '$subcatId', '$mainCatId'),";
  23.                 }
  24.                 $query = substr(trim($query), 0, -1);
  25.                 if (mysql_query($query)) {
  26.                     $torrentLinks = explode("\r\n", $_POST['torrent_links']);
  27.                     $linksCount = count($torrentLinks);
  28.                     if ($linksCount != 0) {
  29.                         $query = "INSERT INTO torrent_links(torrent_link, data_id) VALUES ";
  30.                         for ($i = 0; $i < $linksCount; $i++) {
  31.                             $query.="('" . $torrentLinks[$i] . "','" . $dataId . "'), ";
  32.                         }
  33.                         $query = substr(trim($query), 0, -1);
  34.                         if (!mysql_query($query)) {
  35.                             die(mysql_error());
  36.                         }
  37.                     }
  38.                     if ($_FILES['photos']['name'][0] != "") {
  39.                         $photoDir = ROOT_PATH . '/photos/' . $dataId . '/';
  40.                         if (mkdir($photoDir, 0777)) {
  41.                             for ($i = 0; $i < count($_FILES['photos']['name']); $i++) {
  42.                                 $fileName = md5(microtime()) . '.jpg';
  43.                                 $filePath = $photoDir . $fileName;
  44.                                 if (move_uploaded_file($_FILES['photos']['tmp_name'][$i], $filePath)) {
  45.                                     if (!mysql_query("INSERT INTO photos(data_id, filename) VALUES('$dataId', '$fileName')")) {
  46.                                         die(mysql_error() . '::' . __LINE__);
  47.                                     }
  48.                                 }
  49.                             }
  50.                         } else {
  51.                             echo "Невозможно создать директорию: <b>" . ROOT_PATH . '/photos/' . $dataId . '/' . "</b>";
  52.                         }
  53.                     }
  54.                 }
  55.                 else
  56.                     die(mysql_error() . '::' . __LINE__);
  57.             }
  58.             else
  59.                 die(mysql_error() . '::' . __LINE__);
  60.         }
  61.         break;
  62.     case 'list':
  63.         break;
  64.     default:
  65.         header("Location: index.php");
  66.         break;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement