2013-11-27 223 views
0

當我上傳一個名稱爲「äüö.txt」的文件時,ftp-server上的文件名稱爲「-956.txt」。只有當文件的名稱包含特殊字符時纔會發生這種情況。我怎麼解決這個問題?fineuploader - 編碼特殊字符

的HTML代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta charset="utf-8"> 
<script src="jquery-1.10.2.min.js"></script> 
<script src="custom.fineuploader-4.0.3.js" type="text/javascript"></script> 



<script type="text/template" id="qq-template-manual-noedit"> 
<div class="qq-uploader-selector qq-uploader"> 
    <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone> 
     <span>Drop files here to upload</span> 
    </div> 
    <div class="qq-upload-button-selector qq-upload-button"> 
     <div>Upload a file</div> 
    </div> 
    <span class="qq-drop-processing-selector qq-drop-processing"> 
     <span>Processing dropped files...</span> 
     <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span> 
    </span> 
    <ul class="qq-upload-list-selector qq-upload-list"> 
     <li> 
      <div class="qq-progress-bar-container-selector"> 
       <div class="qq-progress-bar-selector qq-progress-bar"></div> 
      </div> 
      <span class="qq-upload-spinner-selector qq-upload-spinner"></span> 
      <span class="qq-upload-file-selector qq-upload-file"></span> 
      <span class="qq-upload-size-selector qq-upload-size"></span> 
      <a class="qq-upload-cancel-selector qq-upload-cancel" href="#">Cancel</a> 
      <span class="qq-upload-status-text-selector qq-upload-status-text"></span> 
     </li> 
    </ul> 
</div> 
</script> 


<script type="text/javascript"> 
    $(document).ready(function() { 
    var manualuploader = $("#fine-uploader-fileUploadEmailCampaigns").fineUploader({ 
     autoUpload: false, 
     multiple: false, 
     template: "qq-template-manual-noedit", 
     editFilename: { 
      enabled: false 
     }, 
     request: { 
      endpoint: 'endpoint.php' 
     }, 
    }); 

    $('#triggerUpload').click(function() { 
     manualuploader.fineUploader('uploadStoredFiles'); 
    }); 


}) 
</script> 

<title>Unbenanntes Dokument</title> 
    <link href="custom.fineuploader-4.0.3.min.css" rel="stylesheet" type="text/css"/> 


</head> 

<body> 
    <div id="fine-uploader-fileUploadEmailCampaigns"> 
</div> 
<div id="triggerUpload" class="btn btn-primary" style="margin-top: 10px;">Upload</div> 

</body> 
</html> 

PHP-代碼:

<?php 

// Include the upload handler class 
require_once "handler.php"; 


$uploader = new UploadHandler(); 

// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp") 
$uploader->allowedExtensions = array(); // all files types allowed by default 

// Specify max file size in bytes. 
$uploader->sizeLimit = 10 * 1024 * 1024; // default is 10 MiB 

// Specify the input name set in the javascript. 
$uploader->inputName = "qqfile"; // matches Fine Uploader's default inputName value  bydefault 

// If you want to use the chunking/resume feature, specify the folder to temporarily  save parts. 
$uploader->chunksFolder = "chunks"; 

$method = $_SERVER["REQUEST_METHOD"]; 
if ($method == "POST") { 
    header("Content-Type: text/plain"); 

    // Call handleUpload() with the name of the folder, relative to PHP's getcwd() 
    $result = $uploader->handleUpload("files"); 

    // To return a name used for uploaded file you can use the following line. 
    $result["uploadName"] = $uploader->getUploadName(); 

    echo json_encode($result); 
} 
else { 
    header("HTTP/1.0 405 Method Not Allowed"); 
} 

?> 

回答

0

我的猜測是,您使用的是寫出來的文件的語言環境($ LANG)不匹配的語言環境你的OS。例如,要在我的開發環境(OS X,Java 7,IntelliJ)中的名稱中正確創建一個非英文字符的文件,我需要確保與我的JVM相關的LANG環境變量是「en_US.UTF-8 「,它與OS X中設置的$ LANG變量相匹配。