Why isn’t the image effaced?

Asked

Viewed 53 times

0

I have a method that’s like this :

public function setPhoto($file)
    {

        $extension = explode('.', $file['name']);
        $extension = end($extension);

        switch ($extension) {

            case "jpg":
            case "jpeg":
            $image = imagecreatefromjpeg($file["tmp_name"]);
            break;

            case "gif":
            $image = imagecreatefromgif($file["tmp_name"]);
            break;

            case "png":
            $image = imagecreatefrompng($file["tmp_name"]);
            break;

        }

        $dist = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 
            "upload" . DIRECTORY_SEPARATOR . 
            "img" . DIRECTORY_SEPARATOR . 
            "products". DIRECTORY_SEPARATOR . 
            $this->getidproduct() . ".jpg";

        $verify = $dist;    

        if(isset($verify)){
           unlink($verify); 
        }   

        imagejpeg($image, $dist);

        imagedestroy($image);

        $this->checkPhoto();

    }





public function checkPhoto()
    {

        if (file_exists(


            $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 
            "upload" . DIRECTORY_SEPARATOR . 
            "img" . DIRECTORY_SEPARATOR . 
            "products" . DIRECTORY_SEPARATOR . 
            $this->getidproduct() . ".jpg"


            )) {

            $url = "/upload/img/products/" . $this->getidproduct() . ".jpg";

        } else {

            $url = "/upload/img/products/product.jpg";

        }

        $this->setdesphoto($url);

        return $this->setdesphoto($url);

    }

Basically it creates an image, and it saves it in some folder. On my website, when I update an image, it calls this method to set the image, and then uses Checkphoto for when to check the images and send the url

My doubt is the following, I know an image, appears on my site quiet, when I set another image, the second image does not appear, and instead still continues to appear the first. I check in the folder that was saved the image, and there is saved the second normally, only it keeps appearing the first one, what can that be? I even deleted the first image from the folder, but it keeps popping up.

  • var_dump($verify); in the line above unlink shows what ? The value shown exists as path ?

  • It basically shows the path of the variable dist that I did above. And yes, the path exists, and it goes there and erases the img from the folder. So I will set another image on the site, look at the folder and there is the second image saved in the folder, but when I look at the site, there is still the first image.

  • but do you confirm that the image exists by the site or by Cpanel ? It is advisable to confirm in the source even, because it may be that your visualization code has problems too.

  • I confirm based that when I look at just htdocs/uploads/ the new image is saved there, and the old one is in the bin already kkk And when I go look is still the old one. Note: the code to visualize nothing else is the variable $dist, IE, in the image I only put a<img src=" < ? php echo $dist ? >" > , the variable dist is the path of the image, understood?

1 answer

-2

Are you sure the problem isn’t in your browser cache? because, if the image is deleted and the new image appears in the folder but does not appear in the browser can only be the browser cache that continues to display the old one. Either clear your browser cache or try to open in another.

  • This does not answer the question. When you have reputation enough, you’ll be able to leave comments on any post but until then, write only answer that no depend on more information of who asked. - Of Revision

  • but does not need more information: "It basically shows the path of the variable dist that I did above. And yes, the path exists, and it goes there and erases the image from the folder. So I will set another image on the site, look at the folder and there is the second image saved in the folder, but when I look at the site, there is still the first image."

  • Your answer is more like a comment. See that it starts with a question: "you are sure the problem is not in your browser cache?"... as the review says: "write only answer that does not depend on more information from the questioner". The answer is not conclusive, it is more of an assumption.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.