Part of the EllisLab Network
   
 
File uploader class: convert to lowercase
Posted: 25 February 2009 07:28 AM   [ Ignore ]  
Summer Student
Total Posts:  30
Joined  02-18-2003

I would like a config option for the file uploader class to convert the extension (and/or filename) of an uploaded file to lowercase or uppercase. In one of my applications I only save the raw_file to my database because I’m converting the uploaded file to different sizes and always assume .jpg and raw_name as my base. When someone suddenly uploads a file with a .JPG extension it is saved that way and I have to check and rename the file in my controller. I think this could also be perfectly done right when uploading.

Profile
 
 
Posted: 25 February 2009 09:07 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

If you use the uploader from the svn, you can now control the filename explicitly.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 25 February 2009 09:24 AM   [ Ignore ]   [ # 2 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

I think it’s best to store the file_name because that is the name used to store your file. Say if you started to encrypt the filename storing the raw_name, that will always lead to non existing files. raw_name and orig_name should be considered as additional data.

Profile
 
 
Posted: 25 February 2009 09:50 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  30
Joined  02-18-2003

I will look into the SVN Version, I just downloaded it.

xwero - 25 February 2009 09:24 AM

I think it’s best to store the file_name because that is the name used to store your file. Say if you started to encrypt the filename storing the raw_name, that will always lead to non existing files. raw_name and orig_name should be considered as additional data.

If I would store the entire filename I would always have to split it up and extract the extension because I create four different sized versions of the uploaded images and differentiate between them by adding the width (e.g. filename_400.jpg) when I include them for specific purposes.

So everytime I use an image I would have to query the ‘file_name’ from the database, split it, add the _WIDTH part, and put it back together. Not really effective. wink

Profile
 
 
Posted: 25 February 2009 10:04 AM   [ Ignore ]   [ # 4 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

I would handle your particular situation as follows.

In the database table i have the fields filename and extension. 

$insert['filename'] = str_replace($data['file_ext'],'',$data['file_name']);
$insert['extension'] = $data['file_ext'];

I would do it this way because then i don’t have to dedicate a table for each file type. How are you going to handle the storage for more than one file type?

Profile
 
 
Posted: 22 June 2009 07:43 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  56
Joined  03-19-2007

The new upload class from svn still does not have ability to edit the extension - or even just make the extension lowercase.

I know I’d find it very useful to know that my uploaded files are all named in lowercase.
Can this be added?

Cheers

Profile
 
 
Posted: 23 June 2009 01:59 AM   [ Ignore ]   [ # 6 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

Tobz you can always use the rename function after you uploaded the file. If lowercasing is explicitly added the processing will require more checks than needed.

A hackish solution is to alter the name before it gets processed by the library

if(count($_FILES) == 1 && $_FILES['fieldname']['error'] == UPLOAD_ERR_OK)
{
   $_FILES[
'fieldname']['name'] = strtolower($_FILES['fieldname']['name']);
}
Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120269 Total Logged-in Users: 34
Total Topics: 126397 Total Anonymous Users: 4
Total Replies: 664725 Total Guests: 338
Total Posts: 791122    
Members ( View Memberlist )