I am trying to get the name of a particular image file that has already been uploaded, not the one being uploaded in the folder to delete the file.
I have looked up all over google. Please help me. It is the last increment i have to make before the end of the day.
I do have the imageurl as http://localhost/public_html/upload/123.jpeg
I have found this as my answer to delete the file but i do not know how to extract the file name
unlink($imagePath . $file_name);
Thank you
You can extract a file name from a path using basename
like this:
basename($imagePath); // output: 123.jpeg
or without the extension:
basename($imagePath, ".jpeg"); // output: 123
<?php
$path = "index.php"; //type file path with extension
$title = basename($path,".php"); // get only title without extension /remove (,".php") if u want display extension
echo $title;
?>
Try it with two way..
First : base_path
unlink(base_url("uploads/".$image_name));
getcwd : Some times absolute path not working.
unlink(getcwd()."/uploads/".$image_name);