SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Upload files and special characters problem

    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:
    //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!

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    don't use the filename provided by the user. Make your own.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    don't use the filename provided by the user. Make your own.
    Thank you for your answer.
    Could be a solution as the name of image is not really important.
    So, what code should I use to achieve this?
    (The issue here is that images with special characters don't show up on the site.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •