从Laravel本地存储中的特定目录中删除文件

时间:2018-01-18 09:36:19

标签: php laravel file

我将文件存储在本地存储中。所以,在/storage/app/public目录。

我将文件存储在/storage/app/public/userId/images;

我使用了php artisan storage:link,因此我可以在视图中访问该文件,在/public/storage/userId/images中拥有此文件夹的快捷方式 在该路径中,我有2张图片 - test.jpgtest2.jpg

我无法在Laravel文档中找到回复,如何从test.jpg删除文件/public/storage/userId/images

我试过这样的方式:

$path = 'public/' . $id . '/diploma';
$files =  Storage::files($path);
return $files;

它让我回复:

[
"public/303030/images/test.jpg"
"public/303030/images/test2.jpg"
]

现在,如何在该阵列上调用Storage::delete('test.jpg')

2 个答案:

答案 0 :(得分:5)

有多种方法可以删除图片

Graph

和其他方式(简单PHP)

import tensorflow as tf
from tensorflow.python.platform import gfile
with tf.Session() as sess:
    model_filename ='PATH_TO_PB.pb'
    with gfile.FastGFile(model_filename, 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        g_in = tf.import_graph_def(graph_def)
LOGDIR='/logs/tests/1/'
train_writer = tf.summary.FileWriter(LOGDIR)
train_writer.add_graph(sess.graph)

如果你想删除超过1张图像

//In laravel 
File::delete($image);
//for specific directory
File::delete('images/' . 'image1.jpg');

了解有关Delete File in Laravel

的更多详细信息

答案 1 :(得分:1)

使用Storage::delete()delete方法接受单个文件名或要从磁盘中删除的文件数组。

Storage::delete($file_to_delete);

可能你想做类似的事情 -

$files =  Storage::files($path);
Storage::delete($files);