Upload images available
This commit is contained in:
committed by
GitHub
parent
11e4339a04
commit
113a6413a8
@ -33,7 +33,7 @@ class formAddFilm extends Form{
|
||||
<input type="number" name="duration" id="duration" placeholder="Duración" required/><pre>'.$errorDuration.'</pre>
|
||||
<input type="text" name="language" id="language" placeholder="Idioma" required/><pre>'.$errorLanguage.'</pre>
|
||||
<input type="text" name="description" id="description" placeholder="Descripción" required/><pre>'.$errorDescription.'</pre>
|
||||
<div class="file">Imagen promocional:<input type="file" name="file" id="file" placeholder="Imagen promocional" /></div><pre>'.$errorImage.'</pre>
|
||||
<div class="file">Imagen promocional:<input type="file" name="archivo" id="file" placeholder="Imagen promocional" /></div><pre>'.$errorImage.'</pre>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<input type="submit" id="submit" value="Añadir pelicula" class="primary" />
|
||||
@ -48,48 +48,6 @@ class formAddFilm extends Form{
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
|
||||
|
||||
/* PROCESAR LA SUBIDA DE IMAGEN
|
||||
$ok = count($_FILES) == 1 && $_FILES['archivo']['error'] == UPLOAD_ERR_OK;
|
||||
if ( $ok ) {
|
||||
$archivo = $_FILES['archivo'];
|
||||
$nombre = $_FILES['archivo']['name'];
|
||||
//1.a) Valida el nombre del archivo
|
||||
$ok = $this->check_file_uploaded_name($nombre) && $this->check_file_uploaded_length($nombre) ;
|
||||
|
||||
// 1.b) Sanitiza el nombre del archivo
|
||||
//$ok = $this->sanitize_file_uploaded_name($nombre);
|
||||
//
|
||||
|
||||
// 1.c) Utilizar un id de la base de datos como nombre de archivo
|
||||
|
||||
// 2. comprueba si la extensión está permitida
|
||||
$ok = $ok && in_array(pathinfo($nombre, PATHINFO_EXTENSION), self::EXTENSIONS);
|
||||
|
||||
// 3. comprueba el tipo mime del archivo correspode a una imagen image
|
||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||
$mimeType = $finfo->file($_FILES['archivo']['tmp_name']);
|
||||
$ok = preg_match('/image\/*./', $mimeType);
|
||||
|
||||
if ( $ok ) {
|
||||
$tmp_name = $_FILES['archivo']['tmp_name'];
|
||||
|
||||
if ( !move_uploaded_file($tmp_name, "../img/films/{$nombre}") ) {
|
||||
$result['img'] = 'Error al mover el archivo';
|
||||
}
|
||||
|
||||
//if ( !copy("../img/tmp/{$nombre}", "/{$nombre}") ) {
|
||||
// $result['img'] = 'Error al mover el archivo';
|
||||
//}
|
||||
|
||||
}else {
|
||||
$result['img'] = 'El archivo tiene un nombre o tipo no soportado';
|
||||
}
|
||||
} else {
|
||||
$result['img'] = 'Error al subir el archivo.';
|
||||
}
|
||||
*/
|
||||
|
||||
$tittle = $this->test_input($datos['tittle']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $tittle)
|
||||
if ( empty($tittle) ) {
|
||||
@ -116,25 +74,44 @@ class formAddFilm extends Form{
|
||||
|
||||
if (count($result) === 0) {
|
||||
$bd = new Film_DAO("complucine");
|
||||
|
||||
//FALTARIA SUBIR LA IMAGEN
|
||||
$exist = $bd-> GetFilm($tittle,$language);
|
||||
if(mysqli_num_rows($exist) != 0){
|
||||
$result[] = "Ya existe una nueva pelicula con el mismo titulo e idioma.";
|
||||
}
|
||||
else{
|
||||
$ok = count($_FILES) == 1 && $_FILES['archivo']['error'] == UPLOAD_ERR_OK;
|
||||
if ( $ok ) {
|
||||
$archivo = $_FILES['archivo'];
|
||||
$nombre = $_FILES['archivo']['name'];
|
||||
//1.a) Valida el nombre del archivo
|
||||
$ok = $this->check_file_uploaded_name($nombre) && $this->check_file_uploaded_length($nombre) ;
|
||||
|
||||
/* PROCESAR SUBIDA DE IMAGEN
|
||||
$tmp_name = $_FILES['img']['tmp_name'];
|
||||
if ( !move_uploaded_file($tmp_name, "../img/films/{$nombre}") ) {
|
||||
$result[] = 'Error al mover el archivo';
|
||||
}
|
||||
//else if ( !copy(DIR_ALMACEN. "/{$nombre}", DIR_ALMACEN_PROTEGIDO. "/{$nombre}") ) {
|
||||
// $result[] = 'Error al mover el archivo';
|
||||
//}
|
||||
*/
|
||||
//else {
|
||||
$bd->createFilm(null, $tittle,$duration,$language,$description, null); //Null hasta tener $nombre
|
||||
// 1.b) Sanitiza el nombre del archivo
|
||||
//$ok = $this->sanitize_file_uploaded_name($nombre);
|
||||
//
|
||||
|
||||
// 1.c) Utilizar un id de la base de datos como nombre de archivo
|
||||
|
||||
// 2. comprueba si la extensión está permitida
|
||||
$ok = $ok && in_array(pathinfo($nombre, PATHINFO_EXTENSION), self::EXTENSIONS);
|
||||
|
||||
// 3. comprueba el tipo mime del archivo correspode a una imagen image
|
||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||
$mimeType = $finfo->file($_FILES['archivo']['tmp_name']);
|
||||
$ok = preg_match('/image\/*./', $mimeType);
|
||||
finfo_close($finfo);
|
||||
|
||||
if ( $ok ) {
|
||||
$tmp_name = $_FILES['archivo']['tmp_name'];
|
||||
|
||||
if ( !move_uploaded_file($tmp_name, "../img/films/{$nombre}") ) {
|
||||
$result['img'] = 'Error al mover el archivo';
|
||||
}
|
||||
|
||||
//if ( !copy("../img/tmp/{$nombre}", "/{$nombre}") ) {
|
||||
// $result['img'] = 'Error al mover el archivo';
|
||||
//}
|
||||
$bd->createFilm(null, $tittle,$duration,$language,$description, $nombre); //Null hasta tener $nombre
|
||||
$_SESSION['message'] = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
@ -148,7 +125,13 @@ class formAddFilm extends Form{
|
||||
</div>
|
||||
";
|
||||
$result = './?state=mf';
|
||||
//}
|
||||
|
||||
}else {
|
||||
$result['img'] = 'El archivo tiene un nombre o tipo no soportado';
|
||||
}
|
||||
} else {
|
||||
$result['img'] = 'Error al subir el archivo.';
|
||||
}
|
||||
|
||||
}
|
||||
$exist->free();
|
||||
|
Reference in New Issue
Block a user