2016-02-22 140 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

如果这有帮助,请将答案标记为“已接受”。谢谢! –