apache_lookup_uri replacement? Not on apache

Hey,

Smarty has run our site for years and I am testing on a server with upgraded php/mysql to make sure it won’t break. All looks good except for one thing, this test server has php as a CGI, so the following function:

apache_lookup_url generates an error. Is there a simple way to simulate this function on php as a cgi?

The full code being used that’s causing an error:


  function _site_path($path) {
    
        $ap = apache_lookup_uri($path);
        return $ap->filename;
    }

I know what the docs say, but can you explain a little more about how you intend to use it?

I’m assuming the filename property can only be populated if you’re calling this on a local Apache host.

It should be pretty trivial to obtain the filename element from the path supplied, but for this to be dynamic we’re going to need to see how your application is laid out.

I think. :stuck_out_tongue:

Sure. Here’s an example:

My product page loops through cd albums and pulls the cover image of the cd. It uses this function to shrink up the image:

$data[‘coverart’] = im_scale(‘/coverart/’ . $data[‘cover_art’],220,220);


 function [B]im_scale[/B] ($path, $width, $height) {
        $outfp = _append_filename($path, $width . "x" . $height);
        $outf = _image_cache($path, $outfp);
        if ($outf!="") return $outfp;
        $outf = [B]_site_path[/B]($outfp);
        $inf = _[B]site_path[/B]($path);
        exec ("cp $inf $outf");
        exec ("/usr/local/bin/mogrify -scale $width" . "x" . "$height $outf");
        return $outfp;
    }

So we call im_scale function which calls the function I provided at the top. So they can pull the path from the apache_lookup_uri function. I hope this helps explain the situation better.

Thank you.

Would $_SERVER[‘DOCUMENT_ROOT’] suffice?


function _site_path($path){
  if(!function_exists('apache_lookup_uri')){
    return $_SERVER['DOCUMENT_ROOT'];
  }
  $ap = apache_lookup_uri($path);
  return $ap->filename;
}

Actually, it appears $_SERVER[‘DOCUMENT_ROOT’] may not exists when PHP is ran as a CGI process.

Hmm.

Fun, huh? Thankfully, it’s just a test server and I will make sure we move to one using apache/apache 2.

Ty for your time, though.

Why don’t you define the site path somewhere so you don’t have to calculate what the path is every time you call the scaling function?