I'm hitting the wall on trying to pull images from another server. We have two servers. Server A contains the php files/website. Server B contains the MySQL database & image files.

I've successfully pulled the data from the DB on Server B to A; however I keep getting a File Error when trying to display the images. I am able to successfully pull in a static image, but not successful with this coding.

File Error!
http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/S657417-1.jpg

As a note, server B does not have a domain name associated with it yet - trying to access via the ip address.

Any thoughts?

<?
		if (!empty($row_AUTO_SKU_WS['Pictures'])) {
			$images = explode(" ", $row_AUTO_SKU_WS['Pictures']);
			$images = str_replace(' ', '', $images); 
			$count = count($images);
			$fullpath = "http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[0];
		}		

		if (isset($images)) {
			if (file_exists($fullpath)) {
				echo "<a href=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[0]."\" rel=\"lightbox[thumbnails]\"><img src=\"http%3A%2F%2F69.80.208.156/birkeys/phpThumb.php?src=/birkeys/dealerservices/images/auto/".$images[0]."&w=375px\" alt=\"\" style=\"border: solid 1px #333; margin-bottom: 11px;\" /></a>";

				$count--;
				$i=1;

				while($i<=$count) {
					if ($images[$i] != "") {
						echo "<a href=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[$i]."\" rel=\"lytebox[thumbnails]\"><img src=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[$i]."&w=116px&h=87\" alt=\"\" style=\"border: solid 1px #333; margin: 0px 11px 11px 0px;\" /></a>";
					}
					$i++;
				}

			} else { echo "File Error!<br/>".$fullpath; }
	
		} else {
			echo "<br/>No Preview Available<br/>";
		}		
?>

Did you actually use "http://xx.xx.xxx.xxx/..." as $fullpath? Because I've got a feeling that wouldn't work. if (file_exists($fullpath)) is being used remember, and by the look of it is returning FALSE.


Also, http%3A%2F%2F69.80.208.156/birkeys/phpThumb.php is a bad href. As php will see all the characters in the URL as literal anyway, you should use "http://69.8..." instead.

if (file_exists($fullpath)) {

Also the above line of code is invalid due to what $fullpath variable contains. It is impossible to use url's in the file_exists. The file exist function is design for relative paths such as
"../../../folder/file.php". For the answer, someone named justin at php.net has made a function that will detect url's. So the link to that code:
http://au2.php.net/manual/en/function.file-exists.php
And your modified code will be:

<?
function url_exists($url) {
    // Version 4.x supported
    $handle   = curl_init($url);
    if (false === $handle)
    {
        return false;
    }
    curl_setopt($handle, CURLOPT_HEADER, false);
    curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
    curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox   
    curl_setopt($handle, CURLOPT_NOBODY, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
    $connectable = curl_exec($handle);
    curl_close($handle);  
    return $connectable;
}
		if (!empty($row_AUTO_SKU_WS['Pictures'])) {
			$images = explode(" ", $row_AUTO_SKU_WS['Pictures']);
			$images = str_replace(' ', '', $images); 
			$count = count($images);
			$fullpath = "http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[0];
		}		

		if (isset($images)) {
			if (url_exists($fullpath)) {
				echo "<a href=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[0]."\" rel=\"lightbox[thumbnails]\"><img src=\"http%3A%2F%2F69.80.208.156/birkeys/phpThumb.php?src=/birkeys/dealerservices/images/auto/".$images[0]."&w=375px\" alt=\"\" style=\"border: solid 1px #333; margin-bottom: 11px;\" /></a>";

				$count--;
				$i=1;

				while($i<=$count) {
					if ($images[$i] != "") {
						echo "<a href=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[$i]."\" rel=\"lytebox[thumbnails]\"><img src=\"http://xx.xx.xxx.xxx/birkeys/dealerservices/images/auto/".$images[$i]."&w=116px&h=87\" alt=\"\" style=\"border: solid 1px #333; margin: 0px 11px 11px 0px;\" /></a>";
					}
					$i++;
				}

			} else { echo "File Error!<br/>".$fullpath; }
	
		} else {
			echo "<br/>No Preview Available<br/>";
		}		
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.