Upload files and special characters problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xamonix
Forum Newbie
Posts: 6
Joined: Fri Sep 24, 2010 8:42 am

Upload files and special characters problem

Post by xamonix »

Hi,
I've got a script to upload images by users. What happens is users usually put special characters on filename like "ç" and "ã". When they do so the filename on server gets weird like this "canóú.jpg". I would like to have some help on this script to remove this special charactres from filename on upload.
Here is the script I got:

Code: Select all

//Send Images

$userfile2=(isset($_FILES['userfile']['tmp_name']) ? $_FILES['userfile']['tmp_name'] : "");
$userfile_name=(isset($_FILES['userfile']['name']) ? $_FILES['userfile']['name'] : "");
$imagesize = $_FILES['userfile']['size'];

if (( $imageenabled == 2 ) || ( ($imageenabled == 1) && (!empty($userfile_name)) ) ) {
$base_Dir = ELPATH.'/images/eventlist/events/';
$sizelimit = $sizelimit*1024; //size limit in kb

if ($imagesize > $sizelimit) {
mosRedirect("index.php?option=$option&Itemid=$Itemid", "Image too big"." ");
}

if (!move_uploaded_file ($_FILES['userfile']['tmp_name'],$base_Dir.$_FILES['userfile']['name']) || !mosChmod($base_Dir.$_FILES['userfile']['name'])) {
mosRedirect("index.php?option=$option&Itemid=$Itemid", _EVENTS_IMAGEFAIL." ");
} else {
$file = $base_Dir.$userfile_name;
//chmod Bild
@chmod ($file, octdec($imagechmod));
//Vorbereiten auf Thumbnailerstellung
$thumbdir = $base_Dir.'small/';
$save = $thumbdir.$userfile_name ;
if ($imageprob = 1) {
$imageprob = TRUE;
} else {
$imageprob = FALSE;
}
if ($gddisabled == 1) {
evlist_imgd::thumb($file, $save, $imagewidth, $imagehight, $imageprob);
}
}
$_POST['datimage'] = $userfile_name ;
}

Thank you for your time!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Upload files and special characters problem

Post by social_experiment »

What about changing the filename to something completely new; a hashed value based on the current time for instance or a random numeric value?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply