public function processUpload($settings, $files) { $default_path = csSettings::getDefaultUploadPath(); foreach ($files as $slug => $file) { if ($file['name']) { $setting = Doctrine::getTable('csSetting')->findOneBySlug($slug); $target_path = $setting->getOption('upload_path'); $target_path = $target_path ? $target_path : $default_path; //If target path does not exist, attempt to create it if (!file_exists($target_path)) { $target_path = mkdir($target_path) ? $target_path : 'uploads'; } $target_path = $target_path . DIRECTORY_SEPARATOR . basename($file['name']); if (!move_uploaded_file($file['tmp_name'], $target_path)) { $this->getUser()->setFlash('error', 'There was a problem uploading your file!'); } else { $setting->setValue(basename($file['name'])); $setting->save(); } } elseif (isset($settings[$slug . '_delete'])) { $setting = Doctrine::getTable('csSetting')->findOneBySlug($slug); unlink($setting->getUploadPath() . '/' . $setting->getValue()); $setting->setValue(''); $setting->save(); } } }
public function getUploadPath() { if ($this['type'] != 'upload') { throw new sfException(sprintf('Cannot get Upload Path for setting of type "%s"', $this['type'])); } $default_path = csSettings::getDefaultUploadPath(); $target_path = $this->getOption('upload_path'); return $target_path ? $target_path : $default_path; }