Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with writing a file into a directory 1

Status
Not open for further replies.

gxydas

Programmer
Jan 15, 2005
76
0
0
GR
Hi all,

I have a PHP script placed in a subdomain of a main domain. The thing I want to do is to copy an image file to a directory under the main domain.
I get these errors:
... is not within the allowed path(s)
Operation not permitted in ...

I guess it's something about the allowed paths, but how can declare this path?

Thanks for your time.
 
Does the username that apache is running under have write access to the directory in question?
 
Wait, is open_basedir being used in the subdomain? It may be restricting things to it's own domain. You'd have to contact the person who administrates the server. Scripts can't change that value. That doesn't sound like an apache issue to me.
 
Thanks danomac for your answers,
i'm new in these things.

The only open_basedir i found is in the php.ini file and it is not being used.
 
What is the exact error message? You've removed fragments of it.

Did you check apache's error log?
 
[client ip here] PHP Warning: copy(): open_basedir restriction in effect. File(path/httpdocs/images/gn18010601.jpg) is not within the allowed path(s): (..path../subdomains/admin/httpdocs:/tmp) in path/subdomains/admin/httpdocs/script1.php on line 44, referer:

[client ip here] PHP Warning: copy(..path../httpdocs/images/gn18010601.jpg): failed to open stream: Operation not permitted in ..path../subdomains/admin/httpdocs/global_news/ins_functions.php on line 44, referer:

I hope i helped.
 
I think found something that may help.
In /var/ there the belowed records:

1) <Directory /var/ <IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
Options -Includes -ExecCGI
</Directory>


2) <Directory /var/ <IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
Options -Includes +ExecCGI
</Directory>
 
I had an error in the 2nd record above. Here is the correct
2) <Directory /var/ <IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_value open_basedir "/var/ </IfModule>
Options -Includes +ExecCGI
</Directory>
 
It is that configuration that is limiting where you can write to. You will have to modify it (although I don't know which one.) It is likely the 'subdomains' you will have to modify.
 
Correction, the <Directory> tag that deals with the subdomains need to be modified.
 
I'll modify it but what should I write in the <Directory> tag.
I'm new in these things.

Thanks again
 
I don't know how your system manages it's subdomains, so you can try this at your own risk. It should allow all subdomains to access it's parent domain, as well as all of its brother/sister domains.

I have no idea how it will affect your system if you add more subdomains.

Back up your existing configuration before making this change.

For #2:
Code:
<Directory  /var/[URL unfurl="true"]www/vhosts/'domain'/subdomains/'subdomain'/httpdocs>[/URL]
   <IfModule sapi_apache2.c>
      php_admin_flag engine on
      php_admin_value open_basedir "/var/[URL unfurl="true"]www/vhosts/'domain'/:/tmp"[/URL]
   </IfModule>
   <IfModule mod_php5.c>
      php_admin_flag engine on
      php_admin_value open_basedir "/var/[URL unfurl="true"]www/vhosts/'domain'/:/tmp"[/URL]
   </IfModule>
   Options -Includes +ExecCGI
</Directory>
 
Hmm. In that case you could try this (it should only allow the image path):

Code:
<Directory  /var/[URL unfurl="true"]www/vhosts/'domain'/subdomains/'subdomain'/httpdocs>[/URL]
   <IfModule sapi_apache2.c>
      php_admin_flag engine on
      php_admin_value open_basedir "/var/[URL unfurl="true"]www/vhosts/'domain'/subdomains/'subdomain'/httpdocs:/var/www/vhosts/'domain'/images/:/tmp"[/URL]
   </IfModule>
   <IfModule mod_php5.c>
      php_admin_flag engine on
      php_admin_value open_basedir "/var/[URL unfurl="true"]www/vhosts/'domain'/subdomains/'subdomain'/httpdocs:/var/www/vhosts/'domain'/images/:/tmp"[/URL]
   </IfModule>
   Options -Includes +ExecCGI
</Directory>

This should only allow the images directory to be accessed. Remember to back up the config before you try it.
 
No it didn't work.
It returned error: failed to open stream: HTTP wrapper does not support writeable connections.

What kind of problem is this?
 
That is a problem with how the PHP script is written. It has nothing to do with apache.

You can't open a file like ' for writing. You have to open it explicitly on the local filesystem to do that (ie. '/var/
That message means that it is not blocking access to that images directory any longer. Now you have to fix the scripts. The PHP forum (forum434) will be of more help now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top