Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts

    Can some assist with url issue: spaces are converted to "%2F"

    Here's the filename code:

    PHP Code:
    filename=" . htmlentities(rawurlencode($file['filename'])) . " 
    Is there a way to modify this to deal with spaces in a filename?

    Should the spaces be removed when the file is uploaded? Here's the upload code:

    PHP Code:
    if (!empty($_FILES)) {
        
    $tempFile $_FILES['Filedata']['tmp_name'];
        if(
    $_REQUEST['folder'] != './')
        
    $targetPath $_SERVER['DOCUMENT_ROOT'] .'/'.$_REQUEST['folder'];
        else
        
    $targetPath $_SERVER['DOCUMENT_ROOT'] .'/';
        
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

            if(!
    file_exists($targetPath))
            
    mkdir(str_replace('//','/',$targetPath), 0755true);

            
    move_uploaded_file($tempFile,$targetFile);
            echo 
    "1"
    Last edited by Daniellez; 10-09-2009 at 09:08 PM.

  • #2
    New Coder
    Join Date
    Jan 2003
    Posts
    39
    Thanks
    0
    Thanked 4 Times in 4 Posts
    you could try replace spaces with a "_" or something...
    and also, if you are going to modify the original filenames, then maybe you should also ensure that file with the same name doesn't exist:
    PHP Code:
    if (!empty($_FILES)) {
        
    $tempFile $_FILES['Filedata']['tmp_name'];
        if(
    $_REQUEST['folder'] != './')
        
    $targetPath $_SERVER['DOCUMENT_ROOT'] . '/' $_REQUEST['folder'] . '/';
        else
        
    $targetPath $_SERVER['DOCUMENT_ROOT'] . '/';

        
    $targetPath str_replace('//','/',$targetPath);

        if(!
    file_exists($targetPath))
          
    mkdir($targetPath0755true);

        
    $_FILES['Filedata']['name'] = preg_replace("/[^-\._a-zA-Z0-9]/""_"trim($_FILES['Filedata']['name'])); //replace any characters not in the list with a _

        
    $targetFile $targetPath $_FILES['Filedata']['name'];

        if (
    preg_match("/(.*)\.(.*)/"$_FILES['Filedata']['name'], $data))
        {
          
    $name trim($data[1]);
          
    $ext trim($data[2]);
        }
        else
        {
          
    $name $_FILES['Filedata']['name'];
          
    $ext "";
        }

        if (
    $ext !== "")
          
    $ext "." $ext;

        
    $suf "";
        
    $i 1;
        while(
    file_exists($targetFile $targetPath $name $suf $ext)) //if file exists append sufix and check again. repeat until file doesn't exist.
          
    $suf "_" $i++;

        
    move_uploaded_file($tempFile$targetFile);
        echo 
    "1"
    V@no.


  •  

    Posting Permissions

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