Ver Mensaje Individual
  #7 (permalink)  
Antiguo 30/06/2008, 18:56
Avatar de Marvin
Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Respuesta: Formulario Para Enviar Imagenes

Sip... vuelvo a ratos :D

Prueba esto por si funciona! (yo no tengo el servidor de correo funcionando en este pc pero por lo menos no me tira errores al agregar las imagenes)

Código PHP:
<?
error_reporting
(E_ALL);
if(
$_POST['submit'] != "Send"){
?>
<html>
<head>
<title>Send an Email</title>
</head>
<body>
<h1>FORMULARIO</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" enctype="multipart/form-data">
<p>Para: 
  <input type="text" name="to" value="" /><br />
De: 
<input type="text" name="from" value="" /><br />
Asunto: 
<input type="text" name="subject" value="" /></p>
<p>Mensaje:<br />
<textarea cols="70" rows="20" name="message"></textarea></p>
<p>Imagen: 
  <input type="file" name="fileatt[]" /></p>
<p>Imagen 2: 
  <input type="file" name="fileatt[]" /></p>
<p>Imagen 3: 
  <input type="file" name="fileatt[]" /></p>
<p>Imagen 4: 
  <input type="file" name="fileatt[]" /></p>
<p>Imagen 5: 
  <input type="file" name="fileatt[]" /></p>
<p>Imagen 6: 
  <input type="file" name="fileatt[]" /></p>
<p><input type="submit" name="submit" value="Send" /></p>

</form>
</body>
</html>  

<html>
<head>
<title>Enviando email </title>
</head>
<body>
<?php
}else{
    
$to      $_POST['to'];
    
$from    $_POST['from'];
    
$subject $_POST['subject'];
    
$message $_POST['message'];

    
$headers "From: $from";

    
$semi_rand md5(time());
    
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

    
$headers .= "\nMIME-Version: 1.0\n" .
        
"Content-Type: multipart/mixed;\n" .
        
" boundary=\"{$mime_boundary}\"";

    
$message "This is a multi-part message in MIME format.\n\n" .
        
"--{$mime_boundary}\n" .
        
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
        
"Content-Transfer-Encoding: 7bit\n\n" .
    
$message "\n\n";

    
$data chunk_split(base64_encode($data));

    
$err 0;
    
$ok 0;
    
$num 0;
    foreach(
$_FILES['fileatt']['tmp_name'] as $tmp_name){
        if(
$tmp_name != ""){
            
$arr[$num]['tmp_name'] = $tmp_name;//nombre temporal
            
$num++;
        }
    }
    
$num 0;
    foreach(
$_FILES['fileatt']['type'] as $type){
        if(
$type != ""){
            
$arr[$num]['type'] = $type;//tipo
            
$num++;
        }
    }
    
$num 0;
    foreach(
$_FILES['fileatt']['name'] as $name){
        if(
$name != ""){
            
$arr[$num]['name'] = $name;//nombre
            
$num++;
        }
    }
    foreach(
$arr as $imagen){
        
$fileatt      $imagen['tmp_name'];
        
$fileatt_type $imagen['type'];
        
$fileatt_name $imagen['name'];
        if (
is_uploaded_file($fileatt)) {
            
$file fopen($fileatt,'rb');
            
$data fread($file,filesize($fileatt));
            
fclose($file);

            
$message .= "--{$mime_boundary}\n" .
                
"Content-Type: {$fileatt_type};\n" .
                
" name=\"{$fileatt_name}\"\n" .

                
"Content-Transfer-Encoding: base64\n\n" .
                
$data "\n\n" .
                
"--{$mime_boundary}--\n";
            
$ok++;
        }else{
            
$err++;
        }
    }

    if (
mail($to$subject$message$headers)) {
        echo 
"<p>El mensaje ha sido enviado ($ok imagen/es adjuntada/as)</p>";
    } else {
        echo 
"<p>El mensaje fue rechazado! ($ok imagen/es)</p>";
    }
?>
</body>
</html>
<?
}
?>
Suerte!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!