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 ?– Isac
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.
– Genielson
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.
– Isac
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?
– Genielson