Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Himanshu_wkd's avatar

PHP updating images

Guys I am updating images in php using button, when I am updating it without doing any changes,then also a image thumbnail is getting created. Ho can I stop it. Because it is not looking good.

0 likes
2 replies
MThomas's avatar

Not sure if you think we are wizards, but it might be helpful if you show us some of your code and tell us what packages you are using... Just so we can help you :)

Himanshu_wkd's avatar

@mthomas I know you guys are wizards, as this forum has helped me a lot in my small programming career.

Here is the code :

function addProductsData($data){
    if($data['id']!=''){
        $sql = "Select * from `product_details` where id = " . $data['id'];
        $tempData =  $this->CommonClass1->ResultWithArrayData($sql);
        // echo "<pre>"; var_dump($tempData);exit;
        if(isset($_FILES['image']['name']) && !empty($_FILES['image']['name']) && $_FILES['image']['name']!=''){    
            $countfiles = count($_FILES['image']['name']);
            $temp = '';
            for($i=0;$i<$countfiles;$i++){
                $uploadpic=date('Y_m_d_h_i_s').'_'.str_replace(' ', '',$_FILES['image']['name'][$i]);
                move_uploaded_file($_FILES['image']['tmp_name'][$i],'uploads/products/'.$uploadpic);
                $temp = $temp . $uploadpic . '#';
            }
            $tempImageName = $tempData[0]['image'] . $temp;
            $sql = "UPDATE `product_details` SET `heading`='".$data['heading']."',`message`='".$data['message']."',`description`='".$data['description']."',`additional`='".$data['additional']."',`image`='".$tempImageName."' WHERE id=".$data['id']."";
            $status =  $this->CommonClass1->NormalQuery($sql);
            return $status;
        }else{
             ;
        }
    }
    else{
        if(isset($_FILES['image']['name']) && !empty($_FILES['image']['name'])){    
            $countfiles = count($_FILES['image']['name']);
            $temp = '';
            for($i=0;$i<$countfiles;$i++){
                $uploadpic=date('Y_m_d_h_i_s').'_'.str_replace(' ', '',$_FILES['image']['name'][$i]);
                move_uploaded_file($_FILES['image']['tmp_name'][$i],'uploads/products/'.$uploadpic);
                $temp = $temp . $uploadpic . '#';
            }
            $data['image']=$temp;
        } 
        return $this->CommonClass1->NormalQuery("INSERT INTO `product_details`(`heading`,`message`,`image`,`description`,`additional`) VALUES ('".$data['heading']."','".$data['message']."','".$data['image']."','".$data['description']."','".$data['additional']."') ");
    }
}

Please or to participate in this conversation.