douluo7366 2010-10-22 17:07
浏览 44
已采纳

需要允许用户对文件顺序进行排序

I have a website where an admin can login and upload photos. All the images are placed in a directory and then on another page, i am cycling through the images and displaying them. The client has asked if there is a way to move the images around and place them in any order they want.

Now looking at the site, i'm not sure what order the files are even being displayed. They are definitely not in alphabetical order by filename.

I basically have 2 questions

  • Is there a standard way that files are sorted or grabbed by using scandir?
  • What is a good solution to allowing a user to sort the photos?
  • 写回答

2条回答 默认 最新

  • dream890110 2010-10-22 17:11
    关注

    The way they are sorted depends on the filesystem and is not usually guaranteed to be consistent.

    You will need to store the desired order somewhere. There are 3 ways I see to do this.

    1. Use a database that stores a desired order and the filename. You can then get a list of filenames sorted by order. If new items are added to the folder, they will not initially have an order. You will need to set the order when they are added.

    2. Soft the files by filename. When the user resorts the files, you will then need to rename them. The easiest way would be to rename them by their index in the desired order.

    3. Use an index file. This would be similar to the database option, but would have a text file in each directory that stores the sorting information. When the user updates the order, you can place all the filenames into the index file in the desired order. You can then just load the index file and display the files in order. If a new file is not in the index file, you can just add it to the end.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?