Advertisement
Guest User

uploadfile.php

a guest
Mar 17th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1.     protected function checkName($file)
  2.     {
  3.         $this->newName = null;
  4.         $nospaces = str_replace(' ', '_', $file['name']);
  5.         if ($nospaces != $file['name']) {
  6.             $this->newName = $nospaces;
  7.         }
  8.         $nameparts = pathinfo($nospaces);
  9.         $extension = isset($nameparts['extension']) ? $nameparts['extension'] : '';
  10.         if (!$this->typeCheckingOn && !empty($this->suffix)) {
  11.             if (in_array($extension, $this->notTrusted) || empty($extension)) {
  12.                 $this->newName = $nospaces . $this->suffix;
  13.             }
  14.         }
  15.         if ($this->renameDuplicates) {
  16.             $name = isset($this->newName) ? $this->newName : $file['name'];
  17.             $existing = scandir($this->destination);
  18.             if (in_array($name, $existing)) {
  19.                 $i = 1;
  20.                 do {
  21.                     $this->newName = $nameparts['filename'] . '_' . $i++;
  22.                     if (!empty($extension)) {
  23.                         $this->newName .= ".$extension";
  24.                     }
  25.                     if (in_array($extension, $this->notTrusted)) {
  26.                         $this->newName .= $this->suffix;
  27.                     }
  28.                 } while (in_array($this->newName, $existing));
  29.             }
  30.         }
  31.     }
  32.    
  33.     protected function moveFile($file)
  34.     {
  35.         $filename = isset($this->newName) ? $this->newName : $file['name'];
  36.         $success = move_uploaded_file($file['tmp_name'], $this->destination ."/".$class."/".$username." - ".$filename);
  37.         if ($success) {
  38.             $result = $file['name'] . ' was succesvol geupload';
  39.             if (!is_null($this->newName)) {
  40.                 $result .= ', en is hernoemd naar ' . $this->newName;
  41.             }
  42.             $result .= '.';
  43.             $this->messages[] = $result;
  44.         } else {
  45.             $this->messages[] = 'Kon het volgende bestand niet uploden: ' . $file['name'];
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement