Example #1
0
                 echo json_encode(array('deleted' => $file->getAttributes()));
                 exit;
             }
         }
     }
     echo json_encode(array('error' => 'Could not delete that file'));
     exit;
 } else {
     if ($mod && $mod === 'upload') {
         if ($token === $_SESSION['token']) {
             $target = isset($_FILES['file']) ? $_FILES['file'] : false;
             if ($target) {
                 $location = FILES_DIR . '/' . $user->getAttribute('user_id') . '/' . $target['name'];
                 if (move_uploaded_file($target['tmp_name'], $location)) {
                     $file = new File();
                     $file->setAttribute('name', $target['name']);
                     $file->setAttribute('location', $location);
                     $test = $file->loadByAttributes();
                     $file->setAttribute('mime_type', $target['type']);
                     $file->setAttribute('size', $target['size']);
                     $file->setAttribute('_user_id', $user->getAttribute('user_id'));
                     $file->setAttribute('created', date('Y:m:d H:i:s'));
                     if ($file->save()) {
                         $file->loadByAttributes();
                         if ($test) {
                             echo json_encode(array('updated' => $file->getAttributes()));
                         } else {
                             echo $file->getJSON();
                         }
                         exit;
                     } else {