$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 { echo json_encode(array('error' => 'Your file was uploaded, but not saved to the database.')); exit; } } } } echo json_encode(array('error' => 'There was a problem uploading your file')); exit; } else { if ($mod && $mod === 'download') { $id = isset($_GET['id']) ? $_GET['id'] : false; if ($id) {