My Objective:
To delete images in a folder that are not listed in a mysql database.
I want this to be able to run when I logout of my portal.
Any idea on how to do this? Thanks
我的目标:删除未在mysql数据库中列出的文件夹中的图像。我希望能够在我注销门户网站时运行。有关如何做到这一点的任何想法?谢谢
The Database
Database Name: Imagelist
数据库数据库名称:Imagelist
id, image, thumbnail
1, image1.jpg, image1thumb.jpg
2, image2.jpg, image2thumb.jpg
3, image3.jpg, image3thumb.jpg
The Folder
Folder Name: images
文件夹文件夹名称:图像
image1.jpg
image1thumb.jpg
image2.jpg
random1.jpg
image2thumb.jpg
image3.jpg
mage3thumb.jpg
random2.jpg
etc...
2 个解决方案
#1
2
You can get image filename in alphabetical order using
您可以使用按字母顺序获取图像文件名
SELECT image, thumbnail FROM imagelist ORDER BY image
SELECT image,thumbnail FROM imagelist ORDER BY image
and later get list of all files using scandir function of php. this will give you all files in directory by default.
然后使用php的scandir函数获取所有文件的列表。这将默认为您提供目录中的所有文件。
then you can fetch row one by one if this matches with array value
然后,如果这与数组值匹配,则可以逐行获取行
If yes, continue to next array value and fecth row
如果是,继续下一个数组值和fecth行
If no, delete file with using unlink php function, then move to next array value till value matches with row value. If it matches continue as above step.
如果不是,使用unlink php函数删除文件,然后移动到下一个数组值,直到值与行值匹配。如果匹配继续如上所述。
This way you can do this task in one mysql query and one dirscan.
这样你就可以在一个mysql查询和一个dirscan中完成这个任务。
#2
0
Scan the folder with readdir and check each path, if this path exists in your table.
使用readdir扫描文件夹并检查每个路径(如果表中存在此路径)。
#1
2
You can get image filename in alphabetical order using
您可以使用按字母顺序获取图像文件名
SELECT image, thumbnail FROM imagelist ORDER BY image
SELECT image,thumbnail FROM imagelist ORDER BY image
and later get list of all files using scandir function of php. this will give you all files in directory by default.
然后使用php的scandir函数获取所有文件的列表。这将默认为您提供目录中的所有文件。
then you can fetch row one by one if this matches with array value
然后,如果这与数组值匹配,则可以逐行获取行
If yes, continue to next array value and fecth row
如果是,继续下一个数组值和fecth行
If no, delete file with using unlink php function, then move to next array value till value matches with row value. If it matches continue as above step.
如果不是,使用unlink php函数删除文件,然后移动到下一个数组值,直到值与行值匹配。如果匹配继续如上所述。
This way you can do this task in one mysql query and one dirscan.
这样你就可以在一个mysql查询和一个dirscan中完成这个任务。
#2
0
Scan the folder with readdir and check each path, if this path exists in your table.
使用readdir扫描文件夹并检查每个路径(如果表中存在此路径)。