Welcome Guest, Not a member yet? Register   Sign In
Move directory and Rename Multiple files
#1

[eluser]Triple_vent[/eluser]
Hi all, sorry for asking not related with codeigniter, but i am building my project with CI hope CI community can help me to solve my problem, thanks
I am creating upload files using with upload file with directory structure like this :

(Category)
- Home Appliance (Bath rooms, Bedrooms)
- Office Appliance
- Vehicle (land vehicles, air vehicles)
-subcategory (Bath rooms)
-item folder Brush
Brush1.jpg
Brush2.jpg
Brush3.jpg
so on….

This mean every newly uploaded files when it’s new (not exist on the subcategory item folder) it create new folder…

What I really confuse is what if user edit the item throught my view (he change the brush folder to Vehicle category with subcategory land vehicle).

After updating database of item, How can I move the brush folder (directory) and rename all brush images to car with number prefix. After image file name ?
#2

[eluser]jedd[/eluser]
I avoided problems like these by having each photo / file (they are much the same in my system) handled like this:

When the file arrives, it is given a UUID, and the file itself is renamed to this UUID.
The original filename is stored in the file table in my DB. This table also (of course) includes a column for the UUID.

My table contains a bunch of other stuff (who, when, confirmed(bool), type, and so on).

This means you can shuffle the meta-information about files (categories, tags, etc) without having to worry about the filename. You also don't have to worry about the filename causing issues locally - clashes with duplicates, clashes with (sub-)category names, file-system naming limitations, and so on.
#3

[eluser]Triple_vent[/eluser]
Thanks for your reply.

Actually yes i can create UUID (generate some unique code) with my file name but, i just trying to make my file is well organized on it folder in the server. i never imagine that my > 1000 file will bunch in one folder at time with computerized and dizzying code on it's name. so yeah i have 2 option for my problem.

1. Creating UUID on its filename.
2. Learning to create a new way (although it need more time to code it).

By the way, thnks for reply my post, at least u give me my first option to solve that Smile
#4

[eluser]jedd[/eluser]
If you use the names of the file as given to it by the end-user, you are buying yourself a lot of work.

You need to cope with sanitising their input, you need to ensure that the filename they've given is compatible with your file system (and writing code that is subsequently portable between NTFS and any *nix file system is .. potentially challenging). You need to handle clashes - not just per user - so you can't just create a directory for each user ID and put their files in there, as they may upload, on separate occasions, two files with the same name (but different content). For example - I have 225 different index.php files on this computer. You need to track the original filename they gave you (so they can identify the file) as well as the filename you had to store the thing to disk with (to avoid clashes, to comply with your FS limitations, to remove slashes or backslashes or backticks or multiple dots, etc). So you're effectively going to be storing the real filename in a table somewhere, as well as the filename you've munged up in order to stick the thing into your filesystem.

Thus you are ineluctably led towards the conclusion that if you're going to use a munged name, then you should use one that's consistently formatted, effectively guaranteed to be unique, and absolutely safe on any file system (even vfat).

You can guess what I'm going to say next, can't you?
#5

[eluser]Triple_vent[/eluser]
That more than enough to answer my post, guess need more research bout my problem, on google...

i really can say anything bout that, you really give me clear solution bout my problem, thanks..

although actually it's not user determine the filename, it basically determine by me, by $config['file_name'] on every uploaded file (codeigniter automatically addprefix on the file if found there are same name, and organized it on different item categories.

but yeah Really need more knowledge to absorb what u really mean bout the compatibility and other ISSUES, all i can say is Thanks..

Have a nice day.




Theme © iAndrew 2016 - Forum software by © MyBB