Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function random($length) {
- $random = "";
- $x = 0;
- while($x < $length){
- $part = rand(1, 3);
- if ($part == 1){
- $a = 48;
- $b = 57;
- }
- if ($part == 2){
- $a = 65;
- $b = 90;
- }
- if ($part == 3){
- $a = 97;
- $b = 122;
- }
- $code_part = chr(rand($a, $b));//letter generation
- //$code_part = chr(rand(48, 122)); letters + punctuation generation
- $x = $x + 1;
- $random .= $code_part;
- }
- return $random;
- }
- if (isset($_POST['submit'])) {
- if (isset($_FILES['file']) && !empty($_FILES['file']['name'])) {
- $file = $_FILES['file']['name'];
- $extention = pathinfo($file, PATHINFO_EXTENSION);
- $file_new = random(5) . "." . $extention;
- $temp = $_FILES['file']['tmp_name'];
- $filesize = $_FILES['file']['size'] / 1024 / 1024;
- $size = number_format($filesize, 3);
- if (in_array(strtolower($extention), array("png","ico","jpeg","jpg","gif"))) {
- if (move_uploaded_file($temp, "../images/news/" . $file_new)) {
- $file_new = urlencode($file_new);
- $file = urlencode($file);
- $upload_e = false;
- } else {
- $upload_e = "Failed to upload.";
- }
- } else {
- $upload_e = "You can't upload that file type!";
- }
- } else {
- $upload_e = "";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment