Gracias.
Código PHP:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {font-family:Verdana, Geneva, sans-serif; font-size:12px;}
h1 {font-size:16px; font-weight:bold;}
.error {color:#F00; font-size:10px;}
.ok {text-align:center;}
</style>
<title>Envio de fotos</title>
</head>
<body>
<?php
$Name = "";
$email = "";
$comentario = "Si lo deseas puedes enviarnos un comentario de la foto.";
if(isset($_POST['submit']))
{
$Name = stripslashes($_POST['Name']);
$email = stripslashes($_POST['email']);
$comentario = stripslashes($_POST['comentario']);
$upload_Name = ereg_replace( "([ ]+)", "", $_FILES['upload']['name']);
$upload_Size = $_FILES['upload']['size'];
$upload_Temp = $_FILES['upload']['tmp_name'];
$upload_Mime_Type = $_FILES['upload']['type'];
$type = substr($upload_Mime_Type, (strpos($upload_Mime_Type,"/"))+1);
$types = array("jpeg","gif","png");
if( (!empty($Name)) && (eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email)) && ($upload_Size > 0) && ($upload_Size <= 512000) && (in_array($type, $types)) )
{
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
$uploadFile = "uploads/".$upload_Name ;
if (!is_dir(dirname($uploadFile)))
{
RecursiveMkdir(dirname($uploadFile));
}
else
{
chmod(dirname($uploadFile), 0777);
}
move_uploaded_file( $upload_Temp , $uploadFile);
chmod($uploadFile, 0644);
//CHANGE THIS TO THE YOUR DOMAIN
$upload_URL = "http://localhost/test/uploads/".$upload_Name ;
//------------
$pfw_header = "From: $email";
$pfw_subject = "Una Foto fue subida";
// CHANGE THIS TO YOUR EMAIL ADDRESS
$pfw_email_to = "newuser@localhost";
//------------
$pfw_message = "email: $email\n"
. "Nombre: $Name\n"
. "Foto: $upload_URL\n"
. "Comentario:\n $comentario\n";
mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
echo "<div class=\"ok\">Gracias la foto se envió correctamente.<br>En brebe será publicada.</div>";
} else {
echo "<div class=\"error\">Por favor corrija los campos marcados en rojo.</div>";
if(empty($Name))
$noname = "Escribe tu nombre";
if(!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email))
$noemail = "Error en E-mail.";
if($upload_Size <= 0)
$cerofoto = "No olvides de enviar tu foto";
if($upload_Size > 512000)
$bigfoto = "500Kb máximo";
if(!in_array($type, $types))
$nofoto = "No es una foto.";
echo "<br>";
}
}
?>
<form method="post" action="<?php echo $SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table width="550" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<td colspan="2">
<div align="center"><h1>Enviar Foto</h1></div></td>
</tr>
<tr>
<td colspan="2"><table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td valign="top">Nombre:</td>
<td><input name="Name" type="text" id="Name" value="<?php echo $Name; ?>" size="30"><div class="error"><?php echo $noname; ?></div></td>
</tr>
<tr>
<td valign="top">E-mail:</td>
<td><input name="email" type="text" id="email2" value="<?php echo $email; ?>" size="30"><div class="error"><?php echo $noemail; ?></div></td>
</tr>
<tr>
<td valign="top">Foto:</td>
<td><input name="upload" type="file" size="30"><div class="error"><?php echo $nofoto; ?> <?php echo $cerofoto; ?> <?php echo $bigfoto; ?></div></td>
</tr>
<tr>
<td valign="top">Comentraio:</td>
<td><label>
<textarea name="comentario" id="comentario" cols="45" rows="10"><?php echo $comentario; ?></textarea>
</label></td>
</tr>
</table>
<div align="center"><br>
<input name="submit" type="submit" value="Enviar">
<br>
<br>
Tamaño Máximo: 2MB</div></td>
</tr>
</table>
</form>
</body>
</html>