上传文件并重命名 [英] upload file and rename

查看:273
本文介绍了上传文件并重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个上传文件表格,它可以拥有与用户想要添加图像一样多的字段,但是说用户意外地推送提交并上传图像(它们被重命名为1.jpg,2.jpg,3.jpg等等,但用户仍然想要上传更多图像.....是否有可能php读取目录并检查文件名是什么,然后重命名从下一个数字开始上传的所有额外图像?


因此,如果已经有1.jpg和2.jpg再次上传图片,则从3.jpg开始等等......我试过寻找这样的东西但是不要知道从哪里开始。


谢谢

ive got an upload file form and it can have as many fields as a user wants to add images but say the user accidently pushes submit and the images upload (they are renamed as 1.jpg, 2.jpg, 3.jpg etc etc) but the user still wants to upload more images.....is it possible for php to read a directory and check what the filenames are and then renamed all extra images that are uploaded starting from the next digit?

so if there is already a 1.jpg and a 2.jpg once more pictures are uploaded it starts from 3.jpg and so forth....ive tried looking for something like this but dont know where to start.

thanks

推荐答案

这里有一些东西可以帮到你:

readdir() - 阅读文档!

你''ll可能还需要爆炸()文件名以获取名称减去它的扩展名。


理论:
Here''s something to get you started:

readdir() - read to documentation!
You''ll probably also need to explode() the file name to get the name minus it''s extension.

Theory:
  1. 使用readdir()遍历目录的文件,
  2. 确定你是否在目录的末尾(我会让你想到的)
  3. 在文件名中找到数字,
  4. 增加数字以用作下一个文件名。



- 标记。


- mark.


ok thanx markus ....一旦得到测试人员生病了回来获取更多建议......再次感谢
ok thanx markus....once ive gotta tester ill come back for more advice......thanks again


@anfetienne


没问题,anfetienne。


- mark。
@anfetienne
No problem, anfetienne.

- mark.


这篇关于上传文件并重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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