static function field($field, $mapping) { if (isset($mapping[$field])) { return $mapping[$field]; } return InflectionComponent::humanize($field); }
private function doUpload() { if (!empty($_FILES)) { $file = $_FILES['uploaded']; $file_name = clean_filename($file['name']); // TODO: mettre le dosser d'upload dans des configs $path = '/uploads/' . date('Y') . '/' . date('m'); $full_path = $path . '/' . duplicate_filename(ROOT . '/www/' . $path, $file_name); $to_path = ROOT . '/www/' . $full_path; @mkdir(dirname($to_path), 0755, true); move_uploaded_file($file['tmp_name'], $to_path); if (isset($_POST['name']) && $_POST['name']) { $name = $_POST['name']; } else { $name = InflectionComponent::humanize(preg_replace('~\\.(.*?)$~', '', $file['name'])); } $info = getimagesize($to_path); $File = new Library(); $File['name'] = $name; $File['path'] = $full_path; $File['width'] = $info[0]; $File['height'] = $info[1]; $File['type'] = $info['mime']; $File->save(); return $File['id']; } }