11.09.2018 Views

Aprender a desarrollar un sitio Web con PHP y MySQL

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if ((isset($_FILES[’photo’][’name’])&&($_FILES[’imagen’][’error’] ==<br />

UPLOAD_ERR_OK))) {<br />

$destino de ruta = ’imágenes/’;<br />

//desplazamiento del archivo del directorio temporal (almacenado<br />

//por defecto) al directorio de destino<br />

move_uploaded_file($_FILES[’imagen’][’tmp_name’],<br />

$destino de ruta.$_FILES[’imagen’][’name’]);<br />

echo "El archivo ".$_FILES[’imagen’][’name’]." Se ha copiado en el<br />

directorio de fotos";<br />

}<br />

else {<br />

echo "El archivo no se ha copiado en el directorio de fotos.";<br />

}<br />

}<br />

$<strong>con</strong>sulta = "INSERT INTO <strong>con</strong>tenido (Título, Fecha, Comentario, Imagen)<br />

VALUES (’".htmlentities(addslashes($_POST[’título’]),<br />

ENT_QUOTES)."’,’".date("Y-m-d H:i:s")."’,’".htmlentities<br />

(addslashes($_POST[’comentario’]), ENT_QUOTES)."’,<br />

’".$_FILES[’imagen’][’name’]."’)";<br />

$resultado = mysqli_query($<strong>con</strong>nect,$<strong>con</strong>sulta);<br />

$iniciar_sesion = mysqli_insert_id($<strong>con</strong>nect);<br />

/* Cierre de la <strong>con</strong>exión */<br />

mysqli_close($<strong>con</strong>nect);<br />

if ($iniciar_sesion != 0) {<br />

echo "La adición del comentario se ha hecho <strong>con</strong> éxito.";<br />

}<br />

else {<br />

echo "El comentario no se ha añadido.";<br />

}<br />

?><br />

volver a la página de añadir<br />

<br />

<br />

La página mostrar_blog.php es:<br />

<br />

<br />

<br />

Blog<br />

<br />

<br />

<br />

Blog<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!