Search code examples
cakephpfile-uploaddocument-root

Uploading files to a domain using form


I have written an application in CakePHP 3.x and there is a form to upload files.

At present, files are being uploaded to WWW_ROOT.'files' which is /app/webroot/files/ path.

To store files separately from core application, I created a subdomain cdn.example.com whose path is like /home/user/example.com/cdn.example.com/.

since, uploading files requires absolute path, how can I get absolute path of the subdomain cdn.example.com same as $_SERVER['DOCUMENT_ROOT']; from example.com?


Solution

  • First check if your server allow to write files from main domain to subdomain.

    You can't get the absolute path of a different domain of the one you deployed your application, you should store the path in a variable or in constant.

    If you really need to store files in another domain/subdomain and any path is blocked you should consider to reupload the files via FTP script.