Forum Moderators: coopster

Message Too Old, No Replies

Single image upload to multiple domains on same server

         

zorro

3:04 am on May 23, 2010 (gmt 0)

10+ Year Member



Can anyone tell me where to start with this:

I am wanting to upload images to more than one domain - all domains are on the same server.
I currently have php code which uploads 1 image at a time to just one folder and resizes the image to 640 x 480 px and stores the name in a mysql database.
I have 15 domains on the server which all use the same database to reference the image filename but to display the image I have to reference the single folder the images are uploaded to on the one domain.
This means that 14 of the domains are having to link to the single domain with images, to show them.
There are only ever 3 domains that would need to reference an image although the 3 may vary.

To get a better understanding...

domain 1 (town - in (state) domain 11 - in (country) domain 15)
domain 2 (town - in (state) domain 11 - in (country) domain 15)

domain 3 (town - in (state) domain 12 - in (country) domain 15)
domain 4 (town - in (state) domain 12 - in (country) domain 15)

domain 5 (town - in (state) domain 13 - in (country) domain 15)
domain 6 (town - in (state) domain 13 - in (country) domain 15)
domain 7 (town - in (state) domain 13 - in (country) domain 15)

domain 8 (town - in (state) domain 14 - in (country) domain 15)
domain 9 (town - in (state) domain 14 - in (country) domain 15)
domain 10 (town - in (state) domain 14 - in (country) domain 15)

domain 11 (state containing domains 1, 2 - in (country) domain 15)
domain 12 (state containing domains 3, 4 - in (country) domain 15)
domain 13 (state containing domains 5, 6, 7 - in (country) domain 15)
domain 14 (state containing domains 8, 9, 10 - in (country) domain 15)

domain 15 (country containg all (states) and (towns) of all domains

All domains use the same master database.
Currently all images are being uploaded to domain 15/images and domains 1 to 14 have to use the path (http://www.domain15.com/images) to get the images.
Domain 15 will always need all images uploaded.
Some images will belong to one of the (state) domains (11 to 14)
Some images will belong to the (town) domains (1 to 10)

For example an image may belong to (town) domain No2 which means it will also belong to (state) domain No11 and (country) domain No15.

To save domains 1 to 14 having to reference domain 15 all the time to access the image I would like to upload the image to the respective domains too! So each domain can reference its own image.
Further example:
If user is on (country) domain 15 and uploads an image which should also belong on (state) domain 12 and (town) domain 3 then the image gets uploaded to those 3 domains (15,12,3)
Or if user is on (state) domain 12 it gets uploaded to (15,12,3) the same.
Or if user is on (town) domain 3 it gets uploaded to (15,12,3) the same

Basically domain 15 will contain all images
domain 12 would contain all images for domain 12, 3 and 4
domain 3 would contain images for 3 only.

I was wondering if I could pass some kind of variable saying if the domain = domain1.com upload image to domain 1, domain 11 and domain 15.
If domain = domain11.com upload image to domain 11 and domain 15 find out which (town) domain it wants to go to 1 or 2 and upload to correct one.
if domain = domain15.com found out which (state) domain it wants to go to (11 to 14) and upload to correct one and find out which (town) domain it want to go to 1 to 10 and upload to correct one.

Any suggestions would be greatly received.

topr8

11:09 am on May 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i'd upload the images to one folder, (ideally above the root of the main site) and then i'd create a vitual folder under each domain which would be 'symbolically linked' to the actual image folder, that way you just upload all images to the image folder and every domain will be able to access all the images.

[en.wikipedia.org...]

zorro

11:36 pm on May 23, 2010 (gmt 0)

10+ Year Member



That sounds good topr8 thanks for that!
Would it matter if there were thousands of images? They are not large between 10 and 60kb and would anything be affected if several different domains were trying to access the same images at the same time?
Thanks in advance!

p.s is there anywhere you can recommend where I can get examples how to do this in php? The wiki link you posted basically just tells you what a symbolic link is.

encyclo

12:48 am on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming you have a dedicated server, you can do this with Apache rather than symlinks:

[httpd.apache.org...]

zorro

11:14 am on May 24, 2010 (gmt 0)

10+ Year Member



No shared server without shell access.

zorro

1:08 pm on May 24, 2010 (gmt 0)

10+ Year Member



OK here is what I have done so far with and without success.

created a file (php.php) in /home/user/public_html/
In this file I place the code:
<?php $success = symlink('/home/user/public_html/xyz', '/home/user/public_html/domain1/xyz');

if ($success)
echo "Symlink was created";
else
echo "Symlink creation failed!";
?>

Ran the above code by typing into browser user/php.php with the "Symlink was created" message returned.

home/user/public_html/domain1/xyz being the virtual folder
and
home/user/public_html/xyz being the folder containg all the images.

To test I put 2 images in home/user/public_html/xyz (1.jpg and 2.jpg)

I then typed into browser address bar domain1/xyz/1.jpg and got 404 error
same with domain1/xyz/2.jpg
SO IT DOESEN'T APPEAR TO BE WORKING FOR ALL OR ANY ITEMS IN A FOLDER.

I then tried symlink('/home/user/public_html/xyz/1.jpg', '/home/user/public_html/domain1/xyz/1.jpg')
THIS WORKED ONLY FOR THIS FILE (1.jpg).

How do i get a request for any image to domain1/xyz/ to go to the public_html/xyz/ folder and find it there?

Alcoholico

2:37 pm on May 24, 2010 (gmt 0)

10+ Year Member



What about using a php image handler, something like:
<?php
$images_dir = '/a/b/c/';
if(!empty($_GET['image'])) {
$image_file = $_GET['image']; ## Should perform some validation here
if(is_file($images_dir.$image_file)){
header('Content-Type: image/jpeg');
echo file_get_contents($images_dir.$image_file);
}
}
?>

If you wish you could hide it behind a url rewrite, obviously there could be a slightly increased load since you are using a dynamic script to call a static resource.