Foros del Web » Programando para Internet » PHP »

como copiar archivos a un directorio y como optener el nombre de dicho archivo

Estas en el tema de como copiar archivos a un directorio y como optener el nombre de dicho archivo en el foro de PHP en Foros del Web. Hola, estoy haciendo un script para subir varias imagenes a un directorio de el servidor... y tambien guardar los nombres de las imagenes.Extension en la ...
  #1 (permalink)  
Antiguo 17/07/2003, 10:48
Avatar de asinox  
Fecha de Ingreso: enero-2002
Ubicación: Santo Domingo
Mensajes: 2.712
Antigüedad: 22 años, 2 meses
Puntos: 6
como copiar archivos a un directorio y como optener el nombre de dicho archivo

Hola, estoy haciendo un script para subir varias imagenes a un directorio de el servidor... y tambien guardar los nombres de las imagenes.Extension en la base de datos...

Hasta ahora, he logrado guardar las informaciones en la base de datos, pero solo me pone nombres temporales de esta forma (C:Program FilesEasyPHP mpphp6F.tmp ).... ahora bien, como tomo el nombre verdadedor de la imagen y lo meto en la BD en lugar de ese nombre temporal?

y como hago para copiar los archivos en una carpeta especifica?

Saludos
__________________
www.dataautos.com
  #2 (permalink)  
Antiguo 17/07/2003, 11:03
Avatar de 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>"



?>
  #3 (permalink)  
Antiguo 17/07/2003, 11:20
Avatar de asinox  
Fecha de Ingreso: enero-2002
Ubicación: Santo Domingo
Mensajes: 2.712
Antigüedad: 22 años, 2 meses
Puntos: 6
Bueno, gracias, he estado tomando lo que necesito de ahi....

me pueden decir que significa este error:

Warning: Unable to open '1' for reading: No such file or directory in c:\program files\easyphp\www\ms\test2.php on line 21

Saludos
__________________
www.dataautos.com
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:46.