Untitled

mail@pastecode.io avatar
unknown
plain_text
3 months ago
1.9 kB
1
Indexable
Never
<?php

	include_once('model/articles.php');
	include_once('model/images.php');

	$isSend = false;
	$err = '';

	if($_SERVER['REQUEST_METHOD'] === 'POST'){
		$title = trim($_POST['title']);
		$content = trim($_POST['content']);
		$date = date("j F Y");
		$bgcolor = trim($_POST['bg']);
		$file = $_FILES['file'];
		
		if($title === '' || $content === ''|| $date===''|| $bgcolor === '' || $file['name'] === ''){
			$err = 'Заполните все поля!';
		}
		else if($file['size'] === 0){
			$err = 'Файл слишком большой!';
		}
		else if(!checkImageName($file['name'])){
			$err = 'Только jpg';
		}
		else{
			$random_name = mt_rand(1000, 100000);
			addArticle($title, $content, $date, $bgcolor, $random_name.'.jpg');
			copy($file['tmp_name'], 'img/' .$random_name. '.jpg');
			$isSend = true;
		}
	}
	else{
		$title = '';
		$content = '';
	}

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <title>Блог о путешествиях</title>
    <link rel='stylesheet' type='text/css' media='screen' href='css/style.css'>
</head>
<body>
    <header id="h" style="padding: 2% 0;">
        <div class="head_block">
			<? if($isSend): ?>
				<p>Your article is done!</p>
			<? else: ?>
				<form method="post" enctype="multipart/form-data">
					News Title:<br>
					<input type="text" name="title" value="<?=$title?>">
					<br>
					Background color:<br>
					 <input type="color" name="bg" value="#ff0000"><br>
					News Text:<br>
					<textarea name="content" placeholder="Text here..."><?=$content?></textarea>
					<br>
					News Image: <input type="file" name="file"><br>
					<button>Send</button>
					<p><?=$err?></p>
				</form>
			<? endif; ?>
			<a href="index.php">Move to main page</a>
        </div>	
    </header>

</body>
</html>
Leave a Comment