从根文件夹获取映像文件的名称.文件夹名称为upload


Get the name of an image file from the root folder. The name of the folder is upload

我正在尝试获取已经上传的特定图像文件的名称,而不是正在上传的文件夹中删除文件的文件名

我已经在谷歌上查过了。请帮帮我。这是我在一天结束前必须做的最后一个增量。

我确实有imageurl作为http://localhost/public_html/upload/123.jpeg,我发现这是我删除文件的答案,但我不知道如何提取文件名

unlink($imagePath . $file_name);

谢谢

您可以使用basename从路径中提取文件名,如下所示:

 basename($imagePath); // output: 123.jpeg

或不带扩展名:

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;
?>

尝试用两种方式…

First: base_path

unlink(base_url("uploads/".$image_name));

getcwd:有时绝对路径不工作。

unlink(getcwd()."/uploads/".$image_name);