Welcome Guest, Not a member yet? Register   Sign In
filename length, database
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

I upload pictures to server and write their names to database, and when I need them, I get them from database by name.

How do you think what is best practice to organize file name length? I guess 255 should be enougth, so I just should make varchar 255 in database for it and don't care. But I found that there is amiga OS which has 32000 file name length - http://en.wikipedia.org/wiki/Filename But I never heard of it and there is too little chance that user will have that OS so I guess I should not care.

How do you solve such problems?
#2

[eluser]CroNiX[/eluser]
Simple. Limit it to 20 characters. Why on earth would you need a FILENAME to be any larger...even if you can?
Do you really need something like:
nice_day_at_beach_temp_was_75_the_girls_looked_hot_I_stayed_for_an_hour.jpg ?
#3

[eluser]cahva[/eluser]
As an old Amiga user I have to admit that I teased Windows and MS-DOS users back in the days when their filesystem allowed filenames with only 11 chars (8+3) Big Grin I was active Amiga user from 1989 until about 2004 and I still use it sometimes through emulation. But trust me, even amigians dont use that long filenames and 255 characters is enough Smile

I dont recommend restricting the filename to 20 chars. It should be little bit longer than 20 chars as that can be too restrictive(by looking our customers filenames uploaded through CMS or eshop, theres quite long filenames for some). Remember that even if YOU dont use filenames longer than 20 characters, that doesnt mean users doesnt. Make it big enough so 99.9% are covered and give error message to person who exceeds a limit lets say 100 characters.
#4

[eluser]CroNiX[/eluser]
I suppose it really depends on what its being used for.

But, I generally rename uploaded files to something under 20 characters not including file extension.
The rest of the categorization comes from folder names.
Its also good to keep things as short as possible because
1) Different browsers have different maximum character lengths for url resources
2) same thing for web servers
3) same thing for portable devices
4) you want to ensure it can be indexed by all search engines
5) its wasting bandwidth to transmit unnecessary characters, which really can add up
6) now consider 1-5 together

Its also not just the filename that needs to be considered, but the whole URL for things used in images and such.
<img src="http://www.somesite.com/images/users/{userid}/avatars/avatar_01.jpg" alt="My Righteous Avatar" />
The filename is only 13 chars but the url is a lot longer.
#5

[eluser]cahva[/eluser]
The main point is that "less restrictive"="more user friendly" (this applies to all user inputtable fields) and user is king, right? Smile Your points are good also. I personally hate when people use filenames as "Me and my mom on holiday(greece).JPG" or "Höttösen autokorjaamo-hinnasto 2010.pdf" but "normal" users are like that. They dont think about filesystems, how is it shown on mobile or will it F**kup the url in the browser. But as you said, best thing is to rename the file to more friendly format but if needed, save the original filename to database.
#6

[eluser]SPeed_FANat1c[/eluser]
then about renaming - what technique do you use to avoid duplicates? I now think I could rename them to 1.jpg, 2.jpg and when I add new file, I will have to search in db for the biggest number. Hmm, string manipulation - I'll have drop the exctention. Or maybe I should save it without an extention, even if file does not have extentions it is still the same file. Then I could simply find the biggest number, add 1 to it and save the new file.

Another way would be generate random file name, then check in db if it is not used, which will rarely be, and if not used then save.
#7

[eluser]tonanbarbarian[/eluser]
you could rename the file to the id of the table row (assuming you are using an ID)
or you could use tempnam() to get a temp filename that is unique
#8

[eluser]SPeed_FANat1c[/eluser]
I like the idea with the ID Smile

Edit: but, yeah, its only good when you use one id per picture. In my case the object has an id and it can have up to 6 pictures.
#9

[eluser]tonanbarbarian[/eluser]
then create a folder per record as the id field and use tempnam() to create unique filenames in the folder
i.e.
/1/aseffqwef.jpg
/2/hrtjdtyjdy.jpg

i do this exact same thing in a system i have built




Theme © iAndrew 2016 - Forum software by © MyBB