I have a 2 modules that must share common directory for a specific uploaded files.
instructor.example.com And registrar.example.com
So what I want to know ,is what you guys do to make them have a common directory for the file uploads and where is it directory placed?
Because users from registrar.example.com must able to access the directory of the instructor users , specific directory of uploaded files.
For example name it “instructor_registrar/{instructor-id}/ cause I have OCD.
I already have made my research and I found 1 who has similar problem like mine but they just said “you can put it anywhere”. So I want to know where should I create the directory.
Advertisement
Answer
So I came up with an alternative. Here’s what I did. I have 2 framework in 1 subdomain.
/var/www/staff.example.com/instructor/ /var/www/staff.example.com/registrar/
I created another directory inside:
sudo mkdir /var/www/staff.example.com/uploads/shared_dir/
and set the privacy to 755
sudo chmod -R 755 /var/www/staff.example.com/uploads/shared_dir/
and also set the owner to root
sudo chown -R $USER:$USER /var/www/staff.example.com/uploads/shared_dir/
and set my $upload_path
on file upload model to
$uploadpath = $_SERVER[DOCUMENT_ROOT'].'/uploads/shared_dir/';
because I need to create a personal directory if the user is new. I set all files inside /var/www/ owned by apache and all groups and users and enable read and write files for all members of www-data group to enable to make my mkdir()
before uploading the file.
mkdir($_SERVER['DOCUMENT_ROOT'].'/uploads/shared_dir/'.$_SESSION['user_id'], 0777, true);
(I don’t recommend it but this is what I did)
chown -R www-data:www-data /var/www/ chmod -R g+rw /path/to/webserver/www
That settles my file uploading outside the root or framework.