Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/11/2013, 14:02
disenosergio
 
Fecha de Ingreso: mayo-2013
Mensajes: 75
Antigüedad: 11 años
Puntos: 0
Clase para formulario

Estoy estudiando un poco de php y estaba probando una clase que mostrara y procesara un formulario pero creo que no llega a recoger la información POST.
Os mando el código...

Código:
<!doctype html>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" type="text/css" href="css/principal.css">
</head>
<body>
	<?php include('processimage.php'); ?>
	<?php
		$upload=new Upload;
		$upload->checkSubmit();
	?>
</body>
</html>
y la clase es...

Código:
<?php

	class Upload{

			private $newfile;
			private $submit;


		function checkSubmit(){

			if(isset($_POST['submit'])){
				$this->processForm();
			}else{
				$this->showForm();
			};


		}

		function showForm(){

			echo'
				<div id="wrapper">
				<header>
					<img src="img/horizonte.jpg"/>
				</header>
				<section>
					<form method="POST" action="processimage.php" enctype="multipart/form-data" >
						<input type="file" name="newimage"/>
						<input type="submit" name="submit" value="Subir archivo"/>
				</section>
			</div>
			';

		}

		function processForm(){

						$uploaddir="img/";
						$uploadfile = $uploaddir . basename($_FILES['newimage']['name']);

						if (move_uploaded_file($_FILES['newimage']['tmp_name'], $uploadfile)) {

			    			echo "El archivo es válido y fue cargado exitosamente.\n";
						} else {
			    			echo "¡Posible ataque de carga de archivos!\n";
						}
	}
}
?>