<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Web-Tourist Project [Upload]: Качи файл</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<a href="index.php">Начало</a> | <a href="upload.php">Качи файл</a><br /><br /><br />
<form enctype="multipart/form-data" method="POST" accept-charset="utf-8">
Фаил: <input name="file" type="file"><br />
Описание:<br /><textarea rows="10" cols="50" name="opisanie"></textarea><br />
<input type="submit" name="submit" value="Качи">
</form>
<?php
if (isset($_POST['submit']))
{
$file = basename($_FILES['file']['name']);
$opisanie = htmlspecialchars($_POST['opisanie']);
if (!empty($file) and !empty($opisanie))
{
$format = end(explode(".",$file));
if ($format == "png" or $format == "jpg" or $format == "jpeg" or $format == "gif")
{
$newname = "files/".substr(md5($file.time().date("d.m.Y")), 0, 10).".".$format;
move_uploaded_file($_FILES['file']['tmp_name'], $newname);
$access = "true";
include_once "config.php";
mysql_query("INSERT INTO `files` (`file`,`opisanie`) VALUES ('$newname','$opisanie')") or die(mysql_error());
?>
Файлът е качен успешно.<br />
<a href="<?php echo $newname; ?>" target="_blank"><img src="<?php echo $newname; ?>" width="120" height="96" alt="<?php echo $opisanie; ?>" border="0" /></a><br />
<?php
}
else
{
?>
Грешка: файлът е непозволен формат.<br />
Позволени формати: <b>png</b>, <b>jpg</b>, <b>jpeg</b>, <b>gif</b>.
<?php
}
}
else
{
?>
Грешка: не сте избрали файл или не сте въвели описание.
<?php
}
}
?>