2016-02-22 174 views
0

如何在完成上傳後刪除空格和特殊字符?移除空格和特殊字符 - Dropzone

$ds   = DIRECTORY_SEPARATOR; //1  
$storeFolder = 'arquivos';   //2 

if (!empty($_FILES)) { 
    $tempFile = $_FILES['file']['tmp_name']; 
    $targetPath = dirname(__FILE__) . $ds. $storeFolder . $ds; //4 
    $targetFile = $targetPath. $_FILES['file']['name'];   //5 
    move_uploaded_file($tempFile,$targetFile);     //6 
} 
+0

檢查此鏈接http://stackoverflow.com/a/2960312/4498937 – terbubbs

回答

1

簡單地改變這樣的:

$targetFile = $targetPath. $_FILES['file']['name']; //5 
move_uploaded_file($tempFile,$targetFile); //6 

添加一些名稱的處理。這樣你就可以存儲文件並在同一個地方更改名稱。

$originalName = $_FILES['file']['name']; 
$safeName  = cleanNameFunction($originalName); 
$targetFile = $targetPath . $safeName; //5 
move_uploaded_file($tempFile, $targetFile); //6 

其中cleanNameFunction可以去除空白,例如。
我通常會去除除a-zA-Z0-9之外的所有東西。

function cleanNameFunction($name){ 
    $name = preg_replace("/[^a-zA-Z0-9]+/", "", $name); 
    return $name; 
} 
+0

完美!多謝! :) – Rogerio

+0

如果這有幫助,請將答案標記爲「已接受」。謝謝! –