/** * Uploads a file if we have a valid upload * * @param Jelly $model * @param mixed $value * @param bool $loaded * @return string|NULL */ public function save($model, $value, $loaded) { $original = $model->get($this->name, FALSE); // Upload a file? if (is_array($value) and upload::valid($value)) { if (FALSE !== ($filename = upload::save($value, NULL, $this->path))) { // Chop off the original path $value = str_replace($this->path, '', $filename); // Ensure we have no leading slash if (is_string($value)) { $value = trim($value, '/'); } // Delete the old file if we need to if ($this->delete_old_file and $original != $this->default) { $path = $this->path . $original; if (file_exists($path)) { unlink($path); } } } else { $value = $this->default; } } return $value; }