Alex Beyer
Alex Beyer

Reputation: 147

Obtaining image from other website on server

I have two websites on a hosted server with hostgator. I have website1 which is a website I built to add products, images, and track data from all the website we run. In this website I store the images in the filesystem on the server spot dedicated to this website.

Then I have website2 which is a website for to display a web store we are operating and I have it connect to the database that stores the data from website1 and grabs all the relative paths to the images that are on website1 filesystem. I cannot however get the browser to find these images and display them. It keeps giving me errors image not found.

I'm new to filesystem management using php and its proving to be a little difficult.

I am using this to set the file path to the image on website2.

src='".$_SERVER['DOCUMENT_ROOT']."/website1/public_html/$productIMG'

is there something else I have to do to get it to grab the image and display it or is it even possible to try to do what I am trying to do. Maybe I am missusing the $_SERVER[DOCUMENT_ROOT] someone please help me.

The variable in the path is correct for the path I am trying find but the beginning part is not finding the correct way to the other website.

Here is an example of the link I am getting to an image.

Upvotes: 0

Views: 143

Answers (1)

Supreme Dolphin
Supreme Dolphin

Reputation: 2584

A website cannot take the document root of another website and use it as its source. Website1 obviously has an address e.g www.website1.com. This is the public address that equates to its document root (public_html directory). In order to extract anything from there, you need to www.website1.com/somefolder/somefile.extension from Website2 or anywhere else. That won't let you down.

Upvotes: 1

Related Questions