Jump to content

How to delete file by disregarding the file extention?


bugzy

Recommended Posts

How can I delete a file w/out putting the file extension?

 

for example I have image

 

 

<?php

$filename = "duck.jpeg";

unlink($filename);

?>

 

 

is it possible to just use this

 

 

 

<?php

$filename = "duck";

unlink($filename);

?>

 

 

instead?

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.