Image Is Available In Site B Help

Discussion in 'PHP' started by Rhino13, Jan 21, 2013.

  1. #1
    I have two Classifieds websites that I linked with each other the problem I'm having is getting to show images on Site A to show on site B and visaversa, That is a difficult, as site A couldn't do a file search in site B (security limitation). So, all I can do is not directly displaying image in site B by using <img src="examplesiteb.co.za/images/a.png">, instead refer to a script to check if the image is available in site B, eg: <img src="examplesiteb.co.za/image.php?a.php"> is there any body that could Help me with this
     
    Rhino13, Jan 21, 2013 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Do you know the variable used for the actual image?
    Lets assume its called $img
    You could try the following:
    <?php
     
    $host = $_SERVER['HTTP_HOST'];
     
    $image_url = "http://$host/images/$img";
     
    $image = $image_url;
    if (empty($image)) {
        $image = "http://siteB.com/images/$img"; // Change the url for opposite site or point to a default image
    }
     
    //echo $image;
     
    ?>
    Code (markup):
     
    MyVodaFone, Jan 21, 2013 IP
  3. Rhino13

    Rhino13 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    @MyVodaFone

    Thanks for the quick response, this is the php code that calls in the image(s)

    Line 159-175 is if the images does not exist to use defualt image
    Line 183-218 are the once for listings and details pages. I will see if I can implement yours to this
        $row = sql_fetch_array ($res);
        $custom = array ();
        $design = '';
     
        // 1. start creating output based on cf type
        foreach ($tmp_spec as $key => $info)
        {
            $foo = $tmp_spec[$key]['type'];
            $val = $row[$key];
            $custom[$key] = $val;
            $custom[$key.'_raw'] = $val;    // you can use this raw field to create your own output (eg. $custom['logo_raw'] = 'somefile.jpg')
     
            switch ($foo)
            {
                case 'wysiwyg':
                    if (!empty ($val)) $custom[$key] = bbcode ($val);
                break;
     
                case 'file':
                    if (!empty ($val)) $custom[$key] = "<a href=\"$val\">$val</a>";               
                break;
     
                case 'img':
                    if (!empty ($val))
                    {
                        $opt = explode ('|', $tmp_spec[$key]['option']);
                        $thumb = dirname ($val).'/thumb_'.basename ($val);
                        if ($opt[2])
                            $custom[$key] = "<a href=\"$val\" rel=\"#popup\" height=\"600\" width=\"800\" title=\"Second Hand Cars\"><img src=\"$thumb\" alt=\"Second Hand Cars\" /></a>";
                        else
                            $custom[$key] = "<img src=\"$val\" alt=\"SecondHandCars\" title=\"SecondHandCars\" />";
                    }
                break;
     
                case 'rating':
                    if (!empty ($val)) $custom[$key] = rating_img ($val);
                break;
     
                case 'multi':
                    $fii = explode ("\r\n", $val);
                    $custom[$key] = implode (', ', $fii);
                break;
               
                case 'date':
                    if (($val == '0000-00-00') || empty ($val)) $custom[$key] = ''; else $custom[$key] = convert_date ($val, 1);
                break;
               
                case 'time':
                    $custom[$key] = date ('g:ia', mktime (substr ($val, 0, 2), substr ($val,3,2)));
                break;
               
                case 'event':
                    if (!empty ($val) && ($val != '0000-00-00'))
                    {
                        $r = $row[$key.'_recur'];
                        $f = $row[$key.'_end'];
                        $ds = convert_date ($val, 'long');
                        $df = convert_date ($f, 'long');
                        $ux = convert_date ($val, 'int');
                        $y1 = substr ($val, 0, 4);
                        $y2 = substr ($f, 0, 4);
                        $dayname = date ('l', $ux);
                        $datenumber = date ('jS', $ux);
                        $month = date ('F', $ux);           
     
                        if ($r == 'x') $custom[$key] = sprintf ($event_format['detail_once'], $ds);
                        elseif ($r == 'd') $custom[$key] = sprintf ($event_format['detail_daily'], $ds, $df);
                        elseif ($r == 'w') $custom[$key] = sprintf ($event_format['detail_weekly'], $lang['datetime'][$dayname], $ds, $df);
                        elseif ($r == 'm') $custom[$key] = sprintf ($event_format['detail_monthly'], $datenumber, $ds, $df);
                        else $custom[$key] = sprintf ($event_format['detail_yearly'], $month, $datenumber, $y1, $y2);
                    }
                    else
                        $custom[$key] = '';
                break;
               
                case '_recur':
                case '_event_end':
                    $custom[$key] = '';
                break;
            }
     
            // 2. create design (auto)
            $row['title'] = $tmp_spec[$key]['title'];
            $row['value'] = $custom[$key];
            if (!empty ($row['value'])) $design .= quick_tpl ($tpl_section['detail_format'], $row);
        }
     
        $custom['auto_design'] = $design;
        return $custom;
    }
     
     
    function remove_user_file ($opt_file)
    {
        $foo = explode (',', $opt_file);
        foreach ($foo as $val)
        {
            $fn = safe_receive ($val);
            @unlink ($fn);
        }
    }
     
     
    // get folder location (0, 1000, 2000, etc)
    // $name = folder name, $item_id = item_id, $admin = 0: nothing, 1: add ../ on folder location
    function get_folder ($name, $item_id, $admin = 0)
    {
        $fold = floor ($item_id / 1000) * 1000;
        if ($admin)
            $folder = "./../public/$name/$fold";
        else
            $folder = "./public/$name/$fold";
        if (!@file_exists ($folder)) mkdir ($folder);
        @chmod ($folder, 0777);
        return $folder;
    }
     
     
    // ----------- MISC ----------
     
     
    // create country list
    function get_country_list ($idx = '', $by_name = '', $selectable = 0)
    {
        global $db_prefix, $db_name2, $db_name;
     
        $tmp = array ();
        if ($selectable)
            $res = sql_query ("SELECT * FROM ".$db_name2.".".$db_prefix."country WHERE selectable = 1 ORDER BY country_name ASC");
        else
            $res = sql_query ("SELECT * FROM ".$db_name2.".".$db_prefix."country ORDER BY country_name ASC");
     
        while ($row = sql_fetch_array ($res))
        {
            if ($by_name)
                $tmp[$row['country_name']] = $row['country_name'];
     
            else
                $tmp[$row['idx']] = $row['country_name'];
        }
     
        if ($by_name)
            return create_select_form ('country', $tmp, $by_name, '');
        else
            return create_select_form ('country_idx', $tmp, $idx, '');
    }
    ?>
    PHP:
     
    Rhino13, Jan 21, 2013 IP
  4. Rhino13

    Rhino13 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Sorry here is the correct code
     

    Attached Files:

    Rhino13, Jan 21, 2013 IP