在php中创建文件时删除空格

在php中创建文件时删除空格,php,Php,拜托,我有件事要问你 我需要删除此代码生成的文件的空格。现在原始代码如下所示 $small_file = $image->createFile(' '.$filename); 关键是我需要那个“”,否则它就不行了..我是说代码!现在,我需要的是下面这样的内容,这将允许我在提交之前删除代码中生成的空格 $small_file = $image->REMOVE_SPACES[createFile(' '.$filename)]; function createFile($output

拜托,我有件事要问你

我需要删除此代码生成的文件的空格。现在原始代码如下所示

$small_file = $image->createFile(' '.$filename);
关键是我需要那个“”,否则它就不行了..我是说代码!现在,我需要的是下面这样的内容,这将允许我在提交之前删除代码中生成的空格

$small_file = $image->REMOVE_SPACES[createFile(' '.$filename)];

function createFile($output_filename = null) {
if($this->ext == "JPG" OR $this->ext == "JPEG") {
imageJPEG($this->dst_r, $this->uploaddir.$output_filename, $this->quality);
} elseif($this->ext == "PNG") {
imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
} elseif($this->ext == "GIF") {
imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
}
return $output_filename;
}
$filename = $_FILES['Filedata']['name']; 
所有代码:

function createFile($output_filename = null) {
if($this->ext == "JPG" OR $this->ext == "JPEG") {
imageJPEG($this->dst_r, $this->uploaddir.$output_filename, $this->quality);
} elseif($this->ext == "PNG") {
imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
} elseif($this->ext == "GIF") {
imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
}
return $output_filename;
}

function setUploadDir($dirname) {
$this->uploaddir = $dirname;
}

function flush() {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$filename = $_FILES['Filedata']['name']; 

imagedestroy($this->dst_r);
unlink($targetFile);
imagedestroy($this->img_r);

}

}

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$filename = $_FILES['Filedata']['name']; 
$thumbnail = basename($filename,'.' .$ext) . $ext;
$thumbnail1 = basename($filename);      



move_uploaded_file ($tempFile, $targetFile);

 $image = new Image();
            $image->setFile($targetFile);
            $image->setUploadDir($targetPath);
            $image->resize(640);
$large_file = $image->createFile(' '.$thumbnail1);
            $image->resize(120);
$small_file = $image->createFile('s_'.$thumbnail);
            $image->flush();
}
谢谢你的支持

就这么简单:

$small_file = str_replace(' ', '', $image->createFile(' '.$filename));
删除所有空格

或者,要仅删除前导空格,请执行以下操作:

$small_file = ltrim($image->createFile(' '.$filename));

为什么你的代码没有空格就不能工作?这应该可以正常工作:
$small\u file=$image->createFile($filename)语法明智是的,但如果我这样做,它将不会生成图像。。。createFile函数看起来不允许这样做createFile返回什么?文件名?请让我更新这个问题,这样您可以自己查看您是否意识到
$image->createFile()
$image->REMOVE_SPACES[createFile()]
不同,对吗?它应该类似于
$image->createFile(str_replace(“,”,$filename))
不幸的是,它不会删除空格,但您的代码工作得很完美,我的意思是,只是在我的情况下它不会工作。。!我必须修改我的createFile函数才能正常工作。你能帮我修改我的createFile函数吗?我似乎无法使它工作,我的意思是,如果我删除“”它将不会生成新文件!还有,“似乎不能让它工作”,你有任何错误,等等吗?没有,绝对没有,我没有任何错误,我只是不能做重命名!我的意思是,如果删除“”则不会生成该文件!我用所有的代码更新了答案,我需要的只是$large_文件将文件名作为输出提供给em,没有空格或任何东西..就这么简单..是的,但我不需要下划线。。。我只需要它的形象,因为它是!好的,然后用“”替换u,比如:$small\u file=str\u replace(“,”,$small\u file);你能看看我的代码吗,我已经更新了我的问题,有点!是否要从$large\u文件变量中删除空间?请给我变量名或字符串示例,从中删除空格。
You can remove space from image name or replacing them with underscore "_"  

 $small_file = $image->createFile(' '.$filename);
 $small_file = str_replace(" ","_",$small_file);

It will change all space witn _ in your $small_file string.