Advertisement
AleeFerreira

cls - upload.php

Aug 10th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. <?php
  2. /* Upload da imagem por Thiago Belém. */
  3. header("Content-Type: text/html; charset=utf-8;");
  4.  
  5. $u = $_GET["user"];
  6.  
  7. if (isset($u)) {
  8.  
  9.     $title = mysql_real_escape_string($_POST["title_box"]);
  10.     $price = mysql_real_escape_string($_POST["price_box"]);
  11.     $type = mysql_real_escape_string($_POST["type_box"]);
  12.     $obs = mysql_real_escape_string($_POST["obs_box"]);
  13.    
  14.     $title = utf8_decode($title);
  15.     $price = utf8_decode($price);
  16.     $type = utf8_decode($type);
  17.     $obs = utf8_decode($obs);
  18.  
  19.     $_UP['pasta'] = 'ads/thumbs/';
  20.  
  21.     $_UP['tamanho'] = 1024 * 1024 * 2; // 2Mb
  22.  
  23.     $_UP['extensoes'] = array('jpg', 'png', 'gif');
  24.  
  25.     $_UP['renomeia'] = true;
  26.  
  27.     $_UP['erros'][0] = 'Não houve erro';
  28.     $_UP['erros'][1] = 'O arquivo no upload é maior do que o limite do PHP';
  29.     $_UP['erros'][2] = 'O arquivo ultrapassa o limite de tamanho especifiado no HTML';
  30.     $_UP['erros'][3] = 'O upload do arquivo foi feito parcialmente';
  31.     $_UP['erros'][4] = 'Não foi feito o upload do arquivo';
  32.  
  33.     if ($_FILES['file_box']['error'] != 0) {
  34.         die("Não foi possível fazer o upload, erro:<br />" . $_UP['erros'][$_FILES['file_box']['error']]);
  35.         exit;
  36.     }
  37.    
  38.     $extensao = strtolower(end(explode('.', $_FILES['file_box']['name'])));
  39.     if (array_search($extensao, $_UP['extensoes']) === false) {
  40.         echo "Por favor, envie arquivos com as seguintes extensões: jpg, png ou gif";
  41.     }
  42.  
  43.     else if ($_UP['tamanho'] < $_FILES['file_box']['size']) {
  44.         echo "O arquivo enviado é muito grande, envie arquivos de até 2Mb.";
  45.     }
  46.  
  47.     else {
  48.     if ($_UP['renomeia'] == true) {
  49.         $nome_final = time().'.jpg';
  50.     } else {
  51.         $nome_final = $_FILES['file_box']['name'];
  52.     }
  53.  
  54.     if (move_uploaded_file($_FILES['file_box']['tmp_name'], $_UP['pasta'] . $nome_final)) {
  55.         if (!is_null($title) && !is_null($price) && !is_null($type) && !is_null($obs)) {
  56.             $id = time()+1101;
  57.             $n = utf8_decode("À venda");
  58.             include ('connect.php');
  59.            
  60.             $q = mysql_query("insert into ads values ('$id','$title','$u','$type','$price','$nome_final','$n',0,'$obs',0,'')");
  61.             if ($q) {
  62.                 $query = mysql_query("update users set adsid=$id,products=products+1 where username='$u'");
  63.                 if ($query) {
  64.                 ?>
  65.                     <p style="text-align:center;font-family:Trebuchet MS, Sans-Serif;color:#4682B4;font:small-caption;font-size:20px;">Seu anúncio foi cadastrado com sucesso.</p>
  66.                     <p style="text-align:center;font-family:Trebuchet MS, Sans-Serif;color:black;font:small-caption;">Agora é necessário que seu anúncio seja ativado por um administrador!</p>
  67.                     <a href="index.php?pg=anuncios"> < Voltar </a>
  68.                 <?php
  69.                 }
  70.             }
  71.         }
  72.         } else {
  73.             echo "Não foi possível enviar o arquivo, tente novamente";
  74.         }
  75.     }
  76. }
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement