Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

php - Warning: strpos() expects parameter 1 to be string, resource

I recently migrated a PHP site to my server and after migration I receive this error message. As I'm not really familiar with PHP, I'd really appreciate any help. Thanks.

Warning: strpos() expects parameter 1 to be string, resource given in .../public_html/store /product_list.php on line 121

Line 121 is as follows...

$exists = (strpos($handle, "Resource id") !== false) ? true : false;

Here is the rest of the code on the top of the page for relevance.

<?php session_start();
include_once("../includes/define.inc.php");
include("../includes/common.php");
include("../includes/mysql_functions.php");

if( isset( $_GET['category'] ) )
{
    $exists = checkIfExists("aw_category", "aw_category_urlalias='". $_GET['category']."'", "aw_category_id");
    if( !$exists )
    {
        header("Location: " . PRODUCT_LIST );
    }
}


$get_category = ( isset( $_GET['category'] ) ) ? $_GET['category'] : "";
$category_id = ( $get_category == "" ) ? "" : getCategoryIDByAlias( $get_category );
$get_page = (isset($_GET['page']) ) ? $_GET['page'] : 0;


/*category menu*/
$qry_cat = "SELECT aw_category_urlalias, aw_category_id,aw_category_name,aw_category_order,aw_category_status FROM aw_category WHERE aw_category_status = 1 ORDER BY aw_category_order asc";
$result_cat = Query($qry_cat);

/*product*/
$qry_pro = "SELECT *
            FROM aw_product
            INNER JOIN aw_category
            ON aw_product.aw_product_category = aw_category.aw_category_id
            INNER JOIN aw_image
            ON aw_product.aw_product_id = aw_image.aw_img_prodid
            WHERE aw_product.aw_product_status = 1";

if( $category_id == "" ) 
{ //Feature Product
    $qry_pro .= " AND aw_product.aw_product_category = 1";
} else {
    $qry_pro .= " AND aw_product.aw_product_category = ".$category_id."";
}

$qry_pro .= " GROUP BY aw_product.aw_product_id 
            ORDER BY aw_product.aw_product_priority desc,aw_product.aw_product_date desc";

if( $get_category=="" ) 
{ //Feature Product
    $qry_pro .= " LIMIT 6";
}

$result_pro = Query( $qry_pro );
//$row_pro = mysql_fetch_array($result_pro);
$result_pro2 = Query( $qry_pro );

if( !$get_category == "" ) 
{
/*Pagination*/
$num_per_page= 12;
$num_rows = mysql_num_rows($result_pro);

$num_pages = ceil($num_rows/$num_per_page);
$nav = "";


$begin = $get_page * $num_per_page;

$qry_pro .= " LIMIT " . $begin . ",12";
$result_pro = Query( $qry_pro );
$row_pro = mysql_fetch_array($result_pro);

if( $get_page > 0 ) 
{
    $nav ="<a class="page_a" href="".PRODUCT_LIST."?category=".$get_category."&page=".( $get_page-1 )."">&laquo; Previous</a> | ";
}

for($p=0;$p<$num_pages;$p++) 
{
    if($get_page == $p)
        $nav .="<a class="page_a" style='text-decoration:underline' href="".PRODUCT_LIST."?category=".$get_category."&page=".$p."">".($p+1)."</a> | ";
    else
        $nav .="<a class="page_a" href="".PRODUCT_LIST."?category=".$get_category."&page=".$p."">".($p+1)."</a> | ";
}
if($get_page<$num_pages-1)
{
    $nav .="<a class="page_a" href="".PRODUCT_LIST."?category=".$get_category."&page=".($get_page+1).""> Next &raquo;</a>";
}
}//-------
/*news*/
$qry_news = "SELECT aw_news_title FROM aw_news ORDER BY aw_news_date desc LIMIT 8";
$result_news = Query($qry_news);




function getCategoryIDByAlias( $alias )
{
    $query = "SELECT aw_category_id FROM aw_category WHERE aw_category_urlalias='".$alias."'";
    $rs = Query( $query );
    $row = mysql_fetch_array( $rs );
    return $row['aw_category_id'];
}

function checkIfThumbExists( $thumb )
{

    //$exists = ( file_exists( $img_src_thumb ) ) ? true : false;
    //echo $exists;
    //$exists = ( is_file( $img_src_thumb )  ) ? true : false;
    //echo $exists;


    //$AgetHeaders = @get_headers( $img_src_thumb );
    //$exists = ( preg_match( "|200|", $AgetHeaders[0] ) ) ? true : false;
    //echo $exists;


    //$header_response = get_headers($img_src_thumb, 1);
    //$exists = ( strpos( $header_response[0], "404" ) !== false ) ? false : true;; 
    //echo $exists;


    $handle = @fopen($thumb, 'r');
    $exists = (strpos($handle, "Resource id") !== false) ? true : false;

    if( $exists )
    {
        $size = getimagesize( $thumb );

        if( $size[3] == 'width="214" height="214"')
        {
            $exists = true;
        } else {
            $exists = false;
        }

    }
    return $exists;
}


?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try replacing line 121 with the following:

$handle = @file_get_contents($thumb);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...