Reputation: 5943
Problem:
This problem is three-fold.
666
so users can read/write but not execute. The question is, do users really need to read photos? If you are working with database you allow the reading to be done by PHP, not by users. If this is a good case, what permission is then recommended?Code:
Currently when I apply this example to the Cloud9 environment I have to write the folder hardcoded.
$upload_dir = '/home/ubuntu/images/';
While the photos upload with success, I feel that hardcoding the path is not a proper way.
Desired outcome:
To find the path to /images folder that is one level outside document root, set correct permissions for the folder, and access uploaded images according to best-practices in PHP.
Upvotes: 0
Views: 1506
Reputation: 29167
1) How find path:
define ( DOCUMENT_ROOT, realpath(
$_SERVER['DOCUMENT_ROOT']
) . DIRECTORY_SEPARATOR
);
define ( UPLOAD_DIR, realpath(
DOCUMENT_ROOT .
DIRECTORY_SEPARATOR . ".." .
DIRECTORY_SEPARATOR . "images"
) . DIRECTORY_SEPARATOR
);
2) By user is meant in this case, a user who runs the web server. For example, "www-data".
Upvotes: 1