-1

何か聞いてください、

このコードが生成するファイルのスペースを削除する必要があります。これで、元のコードは次のようになります。

$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();
}

ご支援いただきありがとうございます!

4

2 に答える 2

2

次のように簡単です。

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

すべてのスペースを削除するには。

または、先頭のスペースだけを削除するには:

$small_file = ltrim($image->createFile(' '.$filename));
于 2012-08-21T12:00:50.547 に答える
0
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.
于 2012-08-21T12:12:30.893 に答える