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

// Upload
if (isset($_GET['uploaded']))
{
	if (!isset($_FILES['file'])) {
		$error = 'Filen du försökte ladda upp var för stor!';
	
	} else {
		$success = false;
		$file = $_FILES['file'];
		
		$valid_types = array("image/jpeg", "application/zip", "application/x-zip-compressed", 'application/force-download');
		$compressed_types = array("application/zip", "application/x-zip-compressed", 'application/force-download');
		
		if ($file['error'] == UPLOAD_ERR_OK && in_array($file['type'], $valid_types))        // If ok
		{
			if (move_uploaded_file($file['tmp_name'], config::get('gallery', 'uploadPath') . $file['name']))
			{
				if (in_array($file['type'], $compressed_types))
				{
					filehandling::unzip(config::get('gallery', 'uploadPath') . $file['name'], config::get('gallery', 'uploadPath'));
					unlink(config::get('gallery', 'uploadPath') . $file['name']);
				}
				
				$success = true;
			}
		}
		else
		{
			if ($file['error'] == UPLOAD_ERR_OK)
				$error = 'Fel filformat: ' . $file['type'];
			else
				$error = $file['error'];
		}
	}
	
	$system->contentTemplate->set('success', $success);
	
	if (isset($error)) {
		$system->contentTemplate->set('error', $error);
	}
}


// Move from upload directory
filehandling::getFiles(config::get('gallery', 'uploadPath'), $uploaded_files);
if (!empty($uploaded_files))
{
	$system->contentTemplate->set('uploaded', true);
	$pictures = array();
	
	foreach ($uploaded_files as $file)
	{
		$id = $galleryPictures->add($file);
		if ($id !== false)
		{
			$pictures[] = $galleryPictures->get($id);
		}
		else
		{
			$pictures[] = 'Error';
		}
	}
	
	$system->contentTemplate->set('pictures', $pictures);
}


// Save
if (isset($_POST['id']))
{
	$system->contentTemplate->set('saved', false);
	for ($i = 0; $i < count($_POST['id']); $i++)
	{
		$id = $_POST['id'][$i];
		$name = $_POST['name'][$i];
		$tags = $_POST['tags'][$i];
		
		$galleryPictures->edit($id, $name, galleryTags::explodeTags($tags));
	}
	$system->contentTemplate->set('saved', true);
}


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