Jump to content

How to delete file by disregarding the file extention?


bugzy

Recommended Posts

Am I doing this right?

 

It aint working ..

 

<?php

$item_code = mysql_result($result,0,'item_code');

$file = "../images_item/".glob($item_code)."/*.[jpeg][png][gif]";

unlink($file);


?>

 

 

I'm trying to delete ../images_item/item_code.jpeg || .png || .gif

 

 

:shrug:

Since I'm just looking for 3 extension. I just decided to just use an if

 

 

<?php

$png = "../images_item/".$item_id.".png";
$jpeg = "../images_item/".$item_id.".jpeg";
$jpg = "../images_item/".$item_id.".jpg";
$gif = "../images_item/".$item_id.".gif";



                if(file_exists($png))
	{
		unlink($png);
	}
	else if(file_exists($jpeg))
	{
		unlink($jpeg);
	}
	else if(file_exists($jpg))
	{
		unlink($jpg);
	}
	else if(file_exists($gif))
	{
		unlink($gif);
	}


?>

 

 

Btw I'm filtering those images with only .gif .jpeg and .gif only before it will be stored on the directory.

 

I wonder if I'm going to have a problem with this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.