Вот решение проблемы. Чтобы создать отдельную папку для миниатюр, мне пришлось взять изображения из папки «img» и изменить их размер, а затем переместить их в папку с миниатюрами. :))
public function add() {
$data = $this->Department->find('list', array(
'fields' => array('departmentname'),
'contain' => array(
'Department'
)
)
);
$this->set('depdata', $data);
if ($this->request->is('post')) {
if (!empty($this->request->data['Student']['cvsFile'])) {
$cvs = $this->request->data['Student']['cvsFile'];
$ext = substr(strtolower(strrchr($cvs['name'], '.')), 1);
if ($this->Student->validate) {
move_uploaded_file($cvs['tmp_name'], 'files/' . $cvs['name']);
$this->request->data['Student']['cvsFile'] = $cvs['name'];
}
}
if (!empty($this->request->data['Student']['imagePath'])) {
$file = $this->request->data['Student']['imagePath'];
move_uploaded_file($file['tmp_name'], 'img/' . $file['name']);
if ($file['name'] == "") {
}
else {
list($old_width, $old_height) = getimagesize(WWW_ROOT . "img/" . $file['name']);
$new_width = 50;
$new_height = 50;
$ext = substr(strtolower(strrchr($file['name'], '.')), 1);
if ($ext == 'png') {
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefrompng(WWW_ROOT . "img/" . $file['name']);
imagecopyresampled($new_image, $old_image, 0, 0, 0, 1, $new_width, $new_height, $old_width, $old_height);
imagepng($new_image, WWW_ROOT . "img/thumbnail/" . $file['name'], 3);
}
elseif ($ext == 'jpg') {
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefromjpeg(WWW_ROOT . "img/" . $file['name']);
imagecopyresampled($new_image, $old_image, 0, 0, 1, 1, $new_width, $new_height, $old_width, $old_height);
imagejpeg($new_image, WWW_ROOT . "img/thumbnail/" . $file['name'], 30);
}
$this->request->data['Student']['imagePath'] = 'thumbnail/' . $file['name'];
}
if ($this->Student->save($this->request->data)) {
$this->Flash->set("Student has been added.");
$this->redirect(array('action' => 'add'));
}
}
}
}