如何从Laravel 5(URL数据)的Public/Images文件夹中删除图像 [英] How to Delete Images from Public/Images Folder in laravel 5 (URL Data)

查看:256
本文介绍了如何从Laravel 5(URL数据)的Public/Images文件夹中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从laravel 5的public/images文件夹中删除图像文件?

how to delete images file from public/images folder in laravel 5 ??

我从此站点找到了一些示例,但是我知道他们只是在record table中使用文件名,但是我在record table上使用的是URL例如localhost/project/uploads/filename.jpg的名称.所以,如果我这样尝试:

i found some example from this site, but i know they are just using the file name in their record table, but i'm using something like URL e.g localhost/project/uploads/filename.jpg on my record table. so if i tried like this :

    $image_path = $data->image;  // the value is : localhost/project/image/filename.format
    if(File::exists($image_path)) {
        File::delete($image_path);
    }

文件未删除

请帮助

推荐答案

如果要从服务器删除图像,则必须引用目录服务器中文件的位置,这意味着您无法通过url链接引用来删除它.

If you want to delete image from your server, you have to reference location of file in directory server, means you could not reference by url link to delete it.

通常,Laravel 5文件位于 public 文件夹中.

Commonly, Laravel 5 file is locate in public folder.

示例:您的文件位于 public/images

$image_path = "/images/filename.ext";  // Value is not URL but directory file path
if(File::exists($image_path)) {
    File::delete($image_path);
}

如果我可以通过参考URL从服务器删除图像,则Google是第一个目标:)

If I can delete image from server by reference URL then Google is the first target :)

这篇关于如何从Laravel 5(URL数据)的Public/Images文件夹中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆