views:

218

answers:

3

Hi guys,

I have a site on a domain, let's call it "mydomain.com", where people can log in. This domain has a subdomain sub.mydomain.com.

When the user uploads a file on the main domain, I want to move it to the uploads folder on sub.mydomain.com. The folder I want to move the file to has full write/read privileges.

My code that uploads te file:

$filename = 'background_' . $_SESSION['username'] . '.jpg';
if (is_uploaded_file($_FILES['background']['tmp_name'])) 
    {  
        move_uploaded_file($_FILES['background']['tmp_name'], 
        "/var/www/vhosts/mydomain.com/subdomains/sub/httpdocs/uploads/" . $filename);
    }

When running this code I get the following warning/error:

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/var/www/vhosts/mydomain.com/subdomains/sub/httpdocs/uploads/background_User.jpg) is not within the allowed path(s): (/var/www/vhosts/mydomain.com/httpdocs:/tmp) in /var/www/vhosts/dezeactie.nl/httpdocs/opmaak.php  on line 152

Can anybody enlighten me with a solution for my problem?

One final note: I know I could do the login on the subdomain and upload the file there directly, however I would like to keep the login on the main domain for other purposes.

Thanks in advance.

Jurgen

+2  A: 

Your hosting service does not allow your scripts to do stuff outside the httpdocs directory of each virtual host and a shared /tmp directory. That seriously restricts the possibilities for information exchange between sites.

Tricks I can think of:

  1. Store a temporary file in the /tmp directory from the source site and trigger a process in the target site to fetch the file. You can use the curl functions to do so.

  2. Store files in a common database. The storage does not need to be permanent if you think that will affect your site performance. Target site just needs to checke whether it has pending incoming files.

  3. Add files to a queue (perhaps a special directory inside httpdocs) and write a command line script to push them to the target site. Run this command with cron (lets say, once every minutes).

IMHO, #2 looks feasible and reliable.

Álvaro G. Vicario
maybe it's not hosted somewhere where it's impossible to change php.ini?
hop
Thank you for your reply, #2 indeed looks like an option I could have a look at.
Jurgen
A: 

As the error message suggests, file access is limited to certain directories with the open_basedir directive in php.ini.

If you have access to the server's configuration, you can change that.

hop
Eh, yeah, an obvious possibility I had totally overlooked :)
Álvaro G. Vicario
It's unclear to me what you want me to change in open_basedir. Could you give some extra explanations? For instance when I have `/var/www/vhosts/mydomain.com/httpdocs` as the main directory and `/var/www/vhosts/mydomain.com/subdomains/sub/httpdocs` as the subdomain?
Jurgen
@Jurgen: i don't want you to change anything, since i couldn't care less. especially since you don't seem to put any effort into it yourself, not even trying to give a bit more useful information.
hop
Well thanks for the hocus pocus then. Why did you bother to post a reply in the first place, since you'd rather send me on an unknown path than to tell me which way it's heading?
Jurgen
A: 

Why not create a symlink for your subdomain then reach images via sub.domain.com url?

fabrik