bugzy Posted July 18, 2012 Share Posted July 18, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265866-how-to-delete-file-by-disregarding-the-file-extention/ Share on other sites More sharing options...
requinix Posted July 18, 2012 Share Posted July 18, 2012 Use glob to grab all the files matching the duck.* pattern and delete each one. Quote Link to comment https://forums.phpfreaks.com/topic/265866-how-to-delete-file-by-disregarding-the-file-extention/#findComment-1362322 Share on other sites More sharing options...
bugzy Posted July 20, 2012 Author Share Posted July 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265866-how-to-delete-file-by-disregarding-the-file-extention/#findComment-1362922 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Check out glob in the manual. What kind of data does it return? Quote Link to comment https://forums.phpfreaks.com/topic/265866-how-to-delete-file-by-disregarding-the-file-extention/#findComment-1362923 Share on other sites More sharing options...
bugzy Posted July 20, 2012 Author Share Posted July 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265866-how-to-delete-file-by-disregarding-the-file-extention/#findComment-1362934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.