Location: PHPKode > projects > Dev's CMS > devscms/admin/modules/files/upload.php
<?php

$system->contentTemplate->set('success', false);
$system->contentTemplate->set('error', false);

if (isset($_FILES['file']))
{
	$file = $_FILES['file'];
	
	if ($file['error'] == UPLOAD_ERR_OK)
	{
		$new_filename = config::get('files', 'path') . filehandling::stripWeirdCharacters($file['name']);
		$new_filename = filehandling::getUnusedFileName($new_filename);
		
		if (move_uploaded_file($file['tmp_name'], $new_filename))
		{
			$file_title = str_replace(config::get('files', 'path'), '', $new_filename);
			
			if (isset($_POST['id']))
			{
				$file_old = $files->getById($_POST['id']);
				unlink(config::get('files', 'path') . $file_old['filename']);			// Delete old file
				$files->uploadNew($_POST['id'], $file_title, $file['size']);
			}
			else
			{
				$files->upload($file_title, $file['size'], $_POST['title'], $_POST['description']);
			}
			
			header("Location: ?p=f&a=u&success");
		}
		else
		{
			header("Location: ?p=f&a=u&error");
		}
	}
	else
	{
		header("Location: ?p=f&a=u&error");
	}
}
elseif (isset($_GET['success']))
{
	$system->contentTemplate->set('success', true);
}
elseif (isset($_GET['error']))
{
	$system->contentTemplate->set('error', true);
}

// Check if upload folder is writable
if (!is_writable(config::get('files', 'path'))) {
	$system->contentTemplate->set('writable', false);
} else {
	$system->contentTemplate->set('writable', true);
}
Return current item: Dev's CMS