Jump to content

Images function - currently not showing


matthew-marc

Recommended Posts

Hello,

 

I don't have much PHP knowledge so wondered if you could help me...

 

We have a website which has photos of products but the photos are saved in a sub-domain.  The website is www.marcinternational.com.  The images are saved in images.marcinternational.com. They are within a folder called /f/

 

On the previous host, the PHP code was this:

 

function image_root(){
 if($_SERVER['DOCUMENT_ROOT']=='/marcinternational/' ||
   return '//images.marcinternational.com/f';
     }
 }

 

function image_webroot(){
 if($_SERVER['DOCUMENT_ROOT']=='/marcinternational/' || 
   return '//images.marcinternational.com/f';
     }
 }
 
It doesn't work on our new host 1and1.  Can you advise how to change the PHP to point to the images folder when people access the "www.marcinternational.com" website?

 

Thanks

Matthew

Link to comment
Share on other sites

It sounds like you have multiple web root directories seting up into one web server maybe as alias.

 

So, make sure that the "/f" directory is located inside "/marcinternational.com"  not inside "htdocs"

Link to comment
Share on other sites

Thanks for your advice.  Just to explain what the situation is a bit clearer...

 

We have the website: http://marcinternational.com  and it contains products with images.  The images have always been in a separate subdomain: http://images.marcinternational.com (within a folder called "/f")

 

The code as above was for the folders stored on the old hosts system.  We now have a new host, which obviously has a different root file system.

 

How do I get the images in "http://images.marcinternational.com/f" to show up when our staff access the products on "http://www.marcinternational.com"?

 

Here is the full code:

 

<?

function get_imglist($dir,$extns=''){

$exts = split(',',$extns);

if(!is_dir($dir)){return false;}
$handle = opendir($dir);
for(;(false !== ($readdir = readdir($handle))) ;){
if($readdir != '.' && $readdir != '..'){
$path = $dir.'/'.$readdir;
if(is_file($path)){
if($exts){
$ext = strtolower(get_file_extension($readdir));
if(in_array($ext,$exts)){
$lines[] = $readdir;
}
}
}
}
}
closedir($handle);
sort($lines);
return $lines;
}

function get_file_extension($filename){
$from_last_dot = strrpos($filename,'.');
return ($from_last_dot?substr($filename,$from_last_dot+1):'');
}

function md_array_sum($a) {
if(!is_array($a)) return $a;
foreach($a as $key=>$value)
$total += md_array_sum($value);
return $total;
}

function permitted_extns(){
return 'jpg,jpeg,gif,png';
}

function image_root(){
if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' ||
$_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
return '/images.marcinternational.com/f/';
     }
}

function image_webroot(){
if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' ||
$_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
return '/images.marcinternational.com/f/';
     }
}

function get_pictures_by_factory_id($factory_id,$type='orphaned'){
global $mysql;

$root = image_root();
$extns = permitted_extns();
if(!is_dir($root))return false;

switch($type){

case 'product':
$path = $root . '/' . $factory_id;
if(!is_dir($path))return false;
$sql = 'select product_id,picture_available
from products
where deleted_date is null
and picture_available is not null
and trim(picture_available) <> ""
and factory_id = '.$factory_id;
return $mysql->GetRows($sql);
break;

case '':
case 'orphaned':
$path = $root . '/' . $factory_id . '/g';
if(!is_dir($path))return false;
return get_imglist($path,$extns);
break;

}

}

function update_product_picture($product_id,$picture_available){
global $mysql;
$sql = 'update products set picture_available = "'.$picture_available.'" where product_id = '.$product_id;
$mysql->ExecSQL($sql);
}

function delete_product_picture($product_id){
global $mysql;
$sql = 'update products set picture_available = null where product_id = '.$product_id;
$mysql->ExecSQL($sql);
}

function get_random_picture($factory_id){
global $mysql,$user_id;
$sql = 'select picture_available from `products` where factory_id = '.$factory_id.' and picture_available is not null';
if(!$result = $mysql->GetRows($sql))return false;
$row = array_rand($result);
return $result[$row]['picture_available'];
}

?>

Edited by matthew-marc
Link to comment
Share on other sites

No, you cannot save anything in "images.marcinternational.com" b/s it's a not directory.

 

That's an URL point to IP addresses and directories to DNS (Domain Name Server) in your hosting account.

 

So, those statements are completely wrong:

function image_root(){
if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' ||
$_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
return '/images.marcinternational.com/f/';
     }
}

function image_webroot(){
if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' ||
$_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
return '/images.marcinternational.com/f/';
     }
}

Well, if the directory "/f" is a sub-directory of the web root directory named: marcinternational.com you shoud reach that directory by this URL:

http://marcinternational.com/f
    
// or by ip address 
    
http://212.227.212.89/f

If you have one more directory to "/f" containing images just add it to your url address.

 

Then, go to the control panel and make a new record to the DNS pointing to "/f" or "/images" (in case you have a sub-directory with the same name inside "/f")

Edited by jazzman1
Link to comment
Share on other sites

Hi Jazzman, thank you for your help.

 

I have moved the image folder "/f" to the marcinternational.com domain and changed the line in the code to: "return 'http://marcinternational.com/f"

 

1. Is that what you meant?

 

2.  What should be the $_SERVER['DOCUMENT_ROOT']?  Just "/marcinternational.com/" or "http://marcinternational.com/" or the full web server path?  

 

In the hosting companies Control Panel it says:

 

Destination: /marcinternational.com

Complete web server path: /homepages/23/d409796783/htdocs/marcinternational.com

 

Here is the code now:

 

 function image_root(){
 if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' ||
     $_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
     }
 }
 
 function image_webroot(){
 if($_SERVER['DOCUMENT_ROOT']=='/marcinternational.com/' || 
     $_SERVER['DOCUMENT_ROOT']=='/marcltd.com/'){
     }
 }

 

 

3.  Why do I need to add a DNS record and how can this be done?  

 

The only DNS settings I have for the domain are: DNS/CNAME, Nameservers, IP Address, Mail Exchanger, MX1, MX2, MX3, MX4, IPv6.

 

Thanks

Matthew

Edited by matthew-marc
Link to comment
Share on other sites

I have moved the image folder "/f" to the marcinternational.com domain and changed the line in the code to: "return 'http://marcinternational.com/f"

 

1. Is that what you meant?

 

Yes, that's a correct utl address to this directory.

 

 

 

2.What should be the $_SERVER['DOCUMENT_ROOT']?  Just "/marcinternational.com/" or "http://marcinternational.com/" or the full web server path?

 

Yes, you should use the string link given from the server - /homepages/23/d409796783/htdocs/marcinternational.com

 

 

 

3.  Why do I need to add a DNS record and how can this be done?

 

On one web server you would have multiple domain names like - host.com, host1.com, host2.com and so on, but only one of them is set up with primary status.

 

So, all of them could have sub-domains like - sub.host.com, sub.host1.com and so on...

 

So, go to the primary domain with name marcinternational.com and create a new sub-domain with name for example - images.marcinternational.com, then set the proper path to this sub-domain, it could be something like - /f/images (if you have a second folder named images containing yours images).

 

After few minutes (depend of the hosting) the customers could reach those images by web address -images.marcinternational.com/first_image.jpg or with full url address - marcinternational.com/f/images/first_image.jpg

Edited by jazzman1
Link to comment
Share on other sites

On one web server you would have multiple domain names like - host.com, host1.com, host2.com and so on, but only one of them is set up with primary status.

 

I wanted to say, onto one web root directory we might would have multiple domain names, so onto one wed server we could also have multiple web root directories.

 

Sorry about that.

Edited by jazzman1
Link to comment
Share on other sites

Hi Jazzman,

 

I have done those steps but the images are still showing as black squares.  Any idea what could be causing this?

 

In case I've made a mistake, here's the code from the same file as before:

 

<?
 
 function get_imglist($dir,$extns=''){
  
  $exts = split(',',$extns);
  
  if(!is_dir($dir)){return false;}
  $handle = opendir($dir);
  for(;(false !== ($readdir = readdir($handle)));){
   if($readdir != '.' && $readdir != '..'){
    $path = $dir.'/'.$readdir;
    if(is_file($path)){
     if($exts){
      $ext = strtolower(get_file_extension($readdir));
      if(in_array($ext,$exts)){
       $lines[] = $readdir;
      }
     }
    }
   }
  }
  closedir($handle);
  sort($lines);
  return $lines;
 }
 
 function get_file_extension($filename){
  $from_last_dot = strrpos($filename,'.');
  return ($from_last_dot?substr($filename,$from_last_dot+1):'');
 }
 
 function md_array_sum($a) { 
  if(!is_array($a)) return $a; 
  foreach($a as $key=>$value) 
   $total += md_array_sum($value); 
  return $total; 
 } 
 
 function permitted_extns(){
  return 'jpg,jpeg,gif,png';
 }
 
 function image_root(){
 if($_SERVER['DOCUMENT_ROOT']=='/homepages/23/d409796783/htdocs/marcinternational.com' ||
     $_SERVER['DOCUMENT_ROOT']=='/homepages/23/d409796783/htdocs/marcltd.com'){
     }
 }
 
 function image_webroot(){
 if($_SERVER['DOCUMENT_ROOT']=='/homepages/23/d409796783/htdocs/marcinternational.com' || 
     $_SERVER['DOCUMENT_ROOT']=='/homepages/23/d409796783/htdocs/marcinternational.com'){
     }
 }
 
function get_pictures_by_factory_id($factory_id,$type='orphaned'){
 global $mysql;
 
 $root  = image_root();
 $extns = permitted_extns();
 if(!is_dir($root))return false;
  
 switch($type){
 
  case 'product':
   $path = $root . '/' . $factory_id;
   if(!is_dir($path))return false;
   $sql = 'select product_id,picture_available 
           from products 
           where deleted_date is null 
           and picture_available is not null 
           and trim(picture_available) <> ""
           and factory_id = '.$factory_id;
   return $mysql->GetRows($sql);
   break;
 
  case '':
  case 'orphaned':
   $path = $root . '/' . $factory_id . '/g';
   if(!is_dir($path))return false;
   return get_imglist($path,$extns);
   break; 
 
 }
 
}
 
function update_product_picture($product_id,$picture_available){
 global $mysql;
 $sql = 'update products set picture_available = "'.$picture_available.'" where product_id = '.$product_id;
 $mysql->ExecSQL($sql);
}
 
function delete_product_picture($product_id){
 global $mysql;
 $sql = 'update products set picture_available = null where product_id = '.$product_id;
 $mysql->ExecSQL($sql);
}
 
function get_random_picture($factory_id){
 global $mysql,$user_id;
 $sql = 'select picture_available from `products` where factory_id = '.$factory_id.' and picture_available is not null';
 if(!$result = $mysql->GetRows($sql))return false;
 $row = array_rand($result);
 return $result[$row]['picture_available'];
}
 
?>
Link to comment
Share on other sites

 

 

I have done those steps but the images are still showing as black squares.  Any idea what could be causing this?

 

Hard to say without error messages.

 

Put down that one on top of your file - error_reporting(-1);

Link to comment
Share on other sites

Thanks, here is the error:

 

Notice: Constant ADMIN_DOCUMENT_ROOT already defined in /homepages/23/d409796783/htdocs/marcinternational.com/include/_cms_functions.inc.php on line 7

 

<?
$docroot = $_SERVER['DOCUMENT_ROOT'];$site = '';
 
putenv("TZ=GMT");
 
if( strpos($_SERVER['DOCUMENT_ROOT'],'marcinternational.com') ) {
define('ADMIN_DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'] );
Link to comment
Share on other sites

To prevent from this notice shous up, just check if that constant is already difined.

 

Something like:

if (defined('ADMIN_DOCUMENT_ROOT')) {
    // do something when it is defined
} else {
    if (strpos($_SERVER['DOCUMENT_ROOT'], 'marcinternational.com')) {
        define('ADMIN_DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
    }
}

Well, you should also use the mysql_error() function to check what's going on about your queries! 

 

EDIT: Use code tags around your scripts when you're posting the code. That's going to be much more readable for us.

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.