csojunior1996

função que nomeia e move os arquivos

Dec 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. public function addFileToServer($imagem){
  2.  
  3.         $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  4.         $result = '';
  5.         for ($i = 0; $i < 10; $i++)
  6.             $result .= $characters[mt_rand(0, 61)];
  7.  
  8.         $target_dir = $_SERVER['DOCUMENT_ROOT'] . "/ead/assets/images/duvidas/";
  9.         $array = explode('.', $_FILES['imagem']['name']);
  10.         $extension = end($array);
  11.         $target_file = $target_dir . $result . "." . $extension;
  12.         if (move_uploaded_file($_FILES["imagem"]["tmp_name"], $target_file)) {
  13.             echo BASE . "assets/images/duvidas/" . $result . "." . $extension;
  14.         }
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment