最初に関数を削除します。
if($this->isModified())
{
$uploadDir = sfConfig::get('sf_upload_dir');
$thumbnail = new sfThumbnail(150, 150);
$thumbnail->loadFile($uploadDir.'/car/'.$this->getPicture1());
$thumbnail->save($uploadDir.'/car/thumbnail/'. $this->getPicture1());
}
そして、フォームクラスに次の関数を挿入します。
protected function processUploadedFile($field, $filename = null, $values = null) {
// prendo il file che è stato caricato
$fn = parent::processUploadedFile( $field, $filename, $values );
// se il file esiste ed
if ( $fn != "" ) {
try {
// array multidimensionale di tutte le tipologie di thumb esistenti
$thumbnails[] = array( 'dir' => 'ico', 'width' => 75, 'height' => 75 );
$thumbnails[] = array( 'dir' => 'small', 'width' => 150, 'height' => 150 );
$thumbnails[] = array( 'dir' => 'medium', 'width' => 400, 'height' => 400 );
$thumbnails[] = array( 'dir' => 'big', 'width' => 800, 'height' => 800 );
foreach ( $thumbnails as $thumbParam )
{
$currentFile = sfConfig::get( 'sf_upload_dir' ).'/destination_folder/'.$thumbParam[ 'dir' ].'/'. $fn;
if ( is_file( $currentFile ) ) unlink( $currentFile );
}
foreach ( $thumbnails as $thumbParam )
{
$thumbnail = new sfThumbnail( $thumbParam[ 'width' ], $thumbParam[ 'height' ], true, false );
$thumbnail->loadFile( sfConfig::get( 'sf_upload_dir' )."/destination_folder/original/".$fn );
$thumbnail->save( sfConfig::get( 'sf_upload_dir' ).'/destination_folder/'.$thumbParam[ 'dir' ].'/'.$fn, 'image/jpeg' );
}
} catch( Exception $e ) {
}
}
return $fn;
}
ここで
、-配列には必要なすべてのフォルダーが含まれ、それらのディメンションが含まれているため、必要なすべての親指-web /uploadsディレクトリにフォルダー$thumbnails[]
を作成する前に必要ですdestination_folder
また、コマンドを呼び出すことを忘れないでください
php symfony project:permissions
この関数は、フォーム内のすべてのファイルを取得し、必要な数の親指を生成します