Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/07/2003, 11:03
Avatar de Chuty
Chuty
 
Fecha de Ingreso: noviembre-2002
Ubicación: el bar de la esquina
Mensajes: 609
Antigüedad: 21 años, 5 meses
Puntos: 2
Bueno yo utilizo este codigo para copiar archivos y enviarlos a un servidor por ejemplo espero que te sea de ayuda
saludos
Código PHP:
<?php 

$gedgo_path_not 
'C:/chuty/Noticias';
$gedgo_path_art 'C:/chuty/Articulos'

$my_max_file_size "50400"# in bytes 
$image_max_width "270"
$image_max_height "570"

$registered_types = array( 
    
"image/bmp" => ".bmp, .ico"
    
"image/gif" => ".gif"
    
"image/pjpeg" => ".jpg, .jpeg"
    
"image/jpeg" => ".jpg, .jpeg"
    ); 
# these are only a few examples, you can find many more! 

    
$allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg","text/plain"); 

# -- 

    
function form($error=false) { 
        global 
$PHP_SELF,$my_max_file_size$gedgo_path_not$gedgo_path_art$image_max_width$image_max_height

        if (
$error) print $error "<br><br>";
             print 
"\n<form ENCTYPE=\"multipart/form-data\" action=\"" $PHP_SELF "\" method=\"post\">"
             print 
"\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" $my_max_file_size "\">"
             print 
"\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">"
             print 
"\n<BR><b>la Seccion donde Desea Subir el Archivo</b><br>"
             echo 
"<select name=\"the_path\"> <option>Seleccione</option> <option value=\"$gedgo_path_not\">Noticias</option> <option value=\"$gedgo_path_art\">Articulos</option> </select>"
             print 
"\n<P><b>Escoja un Archivo de su disco Duro</b>"
             print 
"\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>"
             print 
"\n<input type=\"submit\" Value=\"Upload\">"
             print 
"\n<BR>NOTA : El Tamño maximo del archivo es : " . ($my_max_file_size 1024) . "KB"; print "\n<BR>NOTA : El Ancho Maximo de la Imagen es de $image_max_width y el Alto maximo es $image_max_height pixels"
             print 
"\n</form>"
    } 
# END form # -- 

    
if (!ereg("^4",phpversion())) { 
            function 
in_array($needle,$haystack) { 
            
# we have this function in PHP4, so for you PHP3 people 
                
for ($i=0$i count($haystack); $i++) { 
                    if (
$haystack[$i] == $needle) { 
                        return 
true
                    } 
                }
            } 
    }     

# -- 

    
function validate_upload($the_file) { 
        global 
$my_max_file_size$image_max_width$image_max_height,$allowed_types,$the_file_type,$registered_types; global $gedgo_path_not$gedgo_path_art
        
$start_error "\n<b>Error:</b>\n<ul>"
            if (
$the_file == "none") { 
                
# do we even have a file? 
                
$error .= "\n<li>You did not upload anything!</li>"
            } 
            else { 
                
# check if we are allowed to upload this file_type 
                
if (!in_array($the_file_type,$allowed_types)) { 
                    
$error .= "\n<li>The file that you uploaded was of a type that is not 
                    allowed, you are only allowed to upload files of the type:\n<ul>"

                    while (
$type current($allowed_types)) { 
                        
$error .= "\n<li>" $registered_types[$type] . " (" $type ")</li>"
                        
next($allowed_types); 
                    } 
                    
$error .= "\n</ul>"
                } 
                if (
ereg("image",$the_file_type) && (in_array($the_file_type,$allowed_types))) { 
                    
$size GetImageSize($the_file); 
                    list(
$foo,$width,$bar,$height) = explode("\"",$size[3]); 
                        if (
$width $image_max_width) { 
                            
$error .= "\n<li>Su imagen no debe ser mas ancha de " $image_max_width " Pixels</li>"
                        } 

                        if (
$height $image_max_height) { 
                            
$error .= "\n<li>Su imagen no debe ser mas alta de " $image_max_height " Pixels</li>"
                        } 
            } 

            if (
$error) { 
                
$error $start_error $error "\n</ul>"; return $error
            } 
            else { 
                return 
false
            } 
    } 
# END validate_upload 
# -- 

function list_files() { 
    global 
$the_path
    
$handle dir($the_path); 
    print 
"\n<b>Uploaded files:</b><br>"
        while (
$file $handle->read()) { 
            if ((
$file != ".") && ($file != "..")) { 
                print 
"\n" $file "<br>"
            } 
        } 
    print 
"<hr>"
    } 

# -- 

function upload($the_file) { 
    global 
$the_path,$the_file_name$gedgo_path_not$gedgo_path_art;; 
    
$error validate_upload($the_file); 
        if (
$error) { 
            
form($error); 
        } 
        else { 
        
# cool, we can continue 
        
echo $the_file;
        echo 
'<br>';
        echo 
$the_path;
        echo 
'<br>';
        echo 
$the_file_name;
            if (!@
copy($the_file$the_path "/" $the_file_name)) { 
                
form("\n<b>Algo esta mal, Verifique los permisos del Directorio $the_path</b>"); 
            } 
            else { 
                echo 
"El archivo <b>$the_file_name</b> se ha subido al directorio <b>$the_path</b> Satisfactoriamente"
                
// list_files(); 
                
form(); 
            } 
        } 


# END upload 
# -- 
############ Start page 
print "<html>\n<head>\n<title>Upload Imagenes</title>\n</head>\n<body>"
    switch(
$task) { 
        case 
'upload'upload($the_file); 
        break; default: 
form(); 
    } 

    print 
"\n</body>\n</html>"



?>