need help with a error

Discussion in 'PHP' started by antpeks, Mar 14, 2009.

  1. #1
    i get the following error, when i try to run a thumbnail script:

    Fatal error: Cannot re-assign $this in /home/xxxxxxxx/domains/xxxxxxx.xxx/public_html/awse/awse_admin/inc.bulk.thumb.php on line 91

    Line 90 and further reads:

    $mext = "\.mpg|\.mpeg|\.avi|\.wmv";
    foreach ($r3[0] as $this) {
        if (eregi("$mext",$this)) {
            $myimg = trim(preg_replace("/.*<img.+?src\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)/is","\\1\\2",$this));
            if (!eregi("^http",$myimg)) {
                $myimg = $base.$myimg;
            }
                $img[$ti] = $myimg;
                $ti++;
        }
    }
    
    
    
        }
    
        if ($ti<=4) {
            $split = 2;
        }
        else {
            $split = 4;
        }
    
        $mid = round($ti/$split);
        $img[$mid] = urlencode(trim($img[$mid]));
            if (!eregi("http",$img[$mid])) {
                $err++;
            }
            else {
                echo "<img src='makethumb.php?gallery_id=$row->gallery_id&url=$img[$mid]' style='margin:10px;' border='1' class='thumb'>\r\n";
                if (!eregi("\.",$gi/10) and $gi>10) {
                    usleep(250000);
                }
                $gi++;
            }
        }
        else {
            $skipped++;
        }
    }
    PHP:
    whole script reads like

    <span class="header">Bulk scan galleries</span>
    <br><br>
    
    <?
    function microtime_float()
    {
       list($usec, $sec) = explode(" ", microtime());
       return ((float)$usec + (float)$sec);
    }
    $time_start = microtime_float();
    
    
    if ($select_stat!="") {
        $wq.= "AND $t_galleries.status='$select_stat' ";
    }
    if (!empty($select_category)) {
        if ($select_category=="-empty-") {
            $wq.= "AND $t_galleries.category_id='0' ";
        }
        else {
            $wq.= "AND $t_galleries.category_id='$select_category' ";
        }
    }
    if (!empty($q)) {
        $wq.= "AND $t_galleries.description like '%$q%' ";
    }
    if (!empty($set_source)) {
        $wq.= "AND $t_galleries.source_type='$set_source' ";
    }
    if (!empty($qurl)) {
        $wq.= "AND $t_galleries.url like '%$qurl%' ";
    }
    
    $wq = trim(eregi_replace("^and |^or ","",$wq));
    if (empty($wq)) { $wq = "$t_galleries.gallery_id!=''"; }
    $sql = @mysql_query("select
            $t_galleries.gallery_id,
            $t_galleries.url
            FROM $t_galleries
            LEFT JOIN $t_categories ON $t_galleries.category_id = $t_categories.category_id
            WHERE $wq
            ORDER BY
            $t_galleries.date DESC,
            $t_galleries.description ASC,
            $t_galleries.url ASC") or die(mysql_error());
    
    include "../class.check.php";
    include "class.fetchlinks.php";
    $gi="0";
    $skipped = 0;
    $err = 0;
    #####################################################
    # Start
    #####################################################
    while ($row = @mysql_fetch_object($sql)) {
        if (!file_exists("../awse_thumbs/$row->gallery_id.jpg")) {
            $img = "";
            $fs = "";
            $snoopy = new Snoopy;
            $snoopy->fetchlinks($row->url);
            $ti=0;
        if (!empty($snoopy->results) and is_array($snoopy->results)) {
                foreach ($snoopy->results as $link) {
                    $link = eregi_replace("&[a-zA-Z0-9]{1,3}=[a-zA-Z0-9]{1,3}/|&[a-zA-Z0-9]{1,3}=[a-zA-Z0-9]{1,3}","",$link);
                    if (!eregi("$link\|\|",$list)) {
                        $list.= "$link||";
                        if (eregi("(.*)(\.jpg|\.png|\.gif|\.jpeg)","$link")) {
                            $img[$ti] = $link;
                            $ti++;
                        }
                    }
                }
        }
    
        if ($ti<=2) {
    $lastslash = strrpos($row->url, "/");
    if ($lastslash != FALSE && $lastslash != 6) {
        $base = substr($row->url, 0, $lastslash+1);
    }
    else {
        $base = $row->url;
    }
    $file = @file_get_contents($row->url);
    
    if (preg_match("/<base.+?href\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)/is", $file, $newbase)) {
         $base = $newbase[1];
    }
    preg_match_all("/<a.+?href\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)<img.+?src\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)/is", $file, $r3);
    
    $mext = "\.mpg|\.mpeg|\.avi|\.wmv";
    foreach ($r3[0] as $this) {
        if (eregi("$mext",$this)) {
            $myimg = trim(preg_replace("/.*<img.+?src\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)/is","\\1\\2",$this));
            if (!eregi("^http",$myimg)) {
                $myimg = $base.$myimg;
            }
                $img[$ti] = $myimg;
                $ti++;
        }
    }
    
    
    
        }
    
        if ($ti<=4) {
            $split = 2;
        }
        else {
            $split = 4;
        }
    
        $mid = round($ti/$split);
        $img[$mid] = urlencode(trim($img[$mid]));
            if (!eregi("http",$img[$mid])) {
                $err++;
            }
            else {
                echo "<img src='makethumb.php?gallery_id=$row->gallery_id&url=$img[$mid]' style='margin:10px;' border='1' class='thumb'>\r\n";
                if (!eregi("\.",$gi/10) and $gi>10) {
                    usleep(250000);
                }
                $gi++;
            }
        }
        else {
            $skipped++;
        }
    }
    #####################################################
    # End
    #####################################################
    $time_end = microtime_float();
    $time = number_format($time_end - $time_start,"2",".",",");
    
    echo "<br><br>\r\n$gi galleries were <font color='green'>thumbed</font> in $time seconds.<br>\r\n";
    echo "$skipped galleries were <font color='red'>skipped</font> (thumbs already existed).<br>\r\n";
    echo "$err galleries returned an <font color='red'>error</font> (hotlink protected, or no images found).<br>\r\n";
    echo "<br><a href='$_SERVER[HTTP_REFERER]'>Click here</a> to return.";
    ?>
    PHP:

    can someone help me out ?

    // Peter
     
    antpeks, Mar 14, 2009 IP
  2. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try replacing it with:

    
    foreach ($r3[0] as $this_var) {
        if (eregi("$mext",$this_var)) {
            $myimg = trim(preg_replace("/.*<img.+?src\\s*=\\s*[\"']?(.*?)[\"']?(\\s+|>)/is","\\1\\2",$this_var));
            if (!eregi("^http",$myimg)) {
                $myimg = $base.$myimg;
            }
                $img[$ti] = $myimg;
                $ti++;
        }
    }
    
    PHP:
     
    steelaz, Mar 14, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $this is a special variable used for OOP. You can't use $this for your own purposes. Just use a different variable name, as steelaz says.
     
    SmallPotatoes, Mar 14, 2009 IP
  4. antpeks

    antpeks Well-Known Member

    Messages:
    394
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #4
    so if i understand correct, then i need to change it every where in the script and the included files to $this_var.

    thanks guys for the quick answer.
     
    antpeks, Mar 14, 2009 IP
  5. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It depends, if $this is used inside of class, then you should leave it as it is. Try running your script and see if it returns any more similar errors.
     
    steelaz, Mar 14, 2009 IP
  6. antpeks

    antpeks Well-Known Member

    Messages:
    394
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #6
    I got it working, perfect help guys. Guess it was clear i am not a Coder / scripter.

    Anyway thousand times thank you.
     
    antpeks, Mar 14, 2009 IP