1

I'm working on an http://example.com/userfiles/upload.php as a file browser for Drupal CKEditor and I want to restrict access to logged-in users but $user->uid inside upload.php doesn't seem to return any value.

I had to add the path /userfiles to Apache's rewrite rules exceptions to be able to access it (as otherwise, it forwards it to index.php?q= and doesn't load).

I don't fully understand yet how the index.php of Drupal works but I suspect that Apache's rewrite rules could be an issue in accessing the $user->uid value?

Or do I need additional code to access this value from Drupal?

$global user;

if (!$user->uid) {
  echo("You're not allowed to upload files");
  die(0);
}

1 Answer 1

1

I have searched lots before but now I came across a post about how to bootstrap Drupal which worked for me. I understand it provides access to the Drupal API.

// Set the working directory.
chdir('/var/www/html/drupalfolder/');
define('DRUPAL_ROOT', getcwd());

// Load Drupal.
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

// Your code will go here ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.