Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I enable writing via PHP to an alias directory.

I have the following on my VirtualHost:

<VirtualHost *:80>
ServerName domain.com
ServerAlias m.domain.com


AliasMatch ^(.*)/user/([a-zA-Z0-9_\-]+)/images/(.*) "C:/Apache/webroot/user/$2/images/$3" 
<Directory "C:/Apache/webroot/user">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all

So if I tried to view a file or an image from m.domain.com I can see it being fetched from the alias directory; however, when I try to write it fails.

for example if i tried something like <?php file_put_contents("user/sam/images/sample.png", $img); ?> it would fail.

Any suggestions or ideas is really appreciated.

share|improve this question

file_put_contents takes a file name, not webserver path. When you put in a relative path from the context of the webserver, it interprets it relative to $_SERVER['DOCUMENT_ROOT'].

To save into an aliased directory, you would need to specify the abolute path of that directory. There is a question about how to get the absolute directory of users public_html folders on StackOverflow

share|improve this answer
A relative path passed to file_put_contents is relative to the CWD, which may or may not be the DOCUMENT_ROOT. – w3dk Oct 8 '13 at 18:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.