CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Automatically change filename in uploads (replace non alphanumerical characters)

Print topic Send  topic

Author Message
pulsorock

Posts: 28
Posted: 06/27/2008, 1:45 PM

Hello,

I'm using the upload components for uploading some images and videos. The problem I'm having is that when people upload files with spaces or special characters in the filename I'm having problem displaying them on my site.

I know that CCS modifies the filename and adds the file uploaded timestamp, but in addition to that, I want to rename the file, I need it to be only alphanumerical numbers and underscores (_).

For example, someones uploads a file named: "video de área prueba del año.flv"
I want it to me renamed to: 200806271527420.video_de__rea_prueba_del_a_o.flv

In other words, any character other than alphanumerical and underscores will be replaced with an underscore (_).

Any idea where I could change this?

Thanks
G
View profile  Send private message
wkempees


Posts: 1679
Posted: 06/27/2008, 2:04 PM

Short answer:
using the Search button top of this forum
enter:
rename filename upload
as search term, will give you a few useful posts.

sorry for short reply am on mobile

walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/28/2008, 8:42 AM

Hi

Here is where you would make that change. I have ran into the same problem and had to fix it also

You can make the fix in Classes.php

In the fileupload object you will see where ActualFileName gets the timestamp added.

After that code use string replace and just replace spaces with the underscore.

Works like a gem.



_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
pulsorock

Posts: 28
Posted: 06/28/2008, 12:09 PM

Thanks, That work....

Added this to the clsFileUpload class:

$replace_filename = array("á", "é", "í", "ó", "ú", "ñ", "Á", "É", "Í", "Ó", "Ú", "Ñ", "¿", "?", "!", "'", " ");

Then modified this line:
$ActualFileName = date("YmdHis") . $index . "." . str_replace($replace_filename, "_", $FileName);
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/28/2008, 3:18 PM

Cool

Glad to help...

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
kirchaj

Posts: 215
Posted: 07/02/2008, 9:13 AM

You Guys Rock!!!!!

This has solved a problem I have had for some time and will save me a lot of emails and frustrated students.

Is this something YES ought to think about implementing?

Thanks again.

TK
View profile  Send private message
jjrjr1


Posts: 942
Posted: 07/02/2008, 9:21 AM

Hi

I sent this fix to YES back in version 3 along with several other fixes like FCKeditor failing on hidden controls, MySql error processing.... etc.

In every case they say they will consider fixing the bugs but they never seem to do it.

We are now on version 4 and no fixes for this and others have appeared.

Have fun..

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
jope

Posts: 3
Posted: 07/23/2008, 12:29 PM

Hi jjrjr1!

Can You post your code? For me it does not work.

excuse me for my englis, i am a beginner :-/
View profile  Send private message
jope

Posts: 3
Posted: 07/24/2008, 2:58 AM

Hi all :-)

Here is my working code:

Add it after this:
// move uploaded file to temporary folder
$file_exists = true;

  
$replacefilenamesrc = (array ("á", "é", "í", "ó", "ö", "ő", "ú", "ü", "ű", "Á", "É", "Í", "Ó", "Ö", "Ő", "Ú", "Ü", "Ű", "ľ", "Ľ", "š", "Š", "č", "Č", "ť", "Ť", "ž", "Ž", "ý", "Ý", "ä", "ň", "Ň", "ô", "ď", "¿", "?", "!", "'", " "));  
$replacefilenamedst = (array ("a", "e", "i", "o", "o", "o", "u", "u", "u", "A", "E", "I", "O", "O", "O", "U", "U", "U", "l", "L", "s", "S", "c", "C", "t", "T", "z", "Z", "y", "Y", "a", "n", "N", "o", "d", "_", "_", "_", "_", " "));  
  
$NewFileName = str_replace($replacefilenamsrc, $replacefilenamedst, $FileName);  
And replace $FileName in the line:
$ActualFileName = date("YmdHis") . $index . "." . $FileName;

with $NewFileName

Final code is:

$ActualFileName = date("YmdHis") . $index . "." . $NewFileName;

8-)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.