Foros del Web » Programando para Internet » PHP »

Cargar Archivos con PHP

Estas en el tema de Cargar Archivos con PHP en el foro de PHP en Foros del Web. Buenas, necesito ayuda para poder cargar archivos utilizando php, en principio me bastaria con cargar archivos con nombres y rutas especificas del pc cliente predefinidos ...
  #1 (permalink)  
Antiguo 28/08/2008, 09:47
 
Fecha de Ingreso: agosto-2008
Ubicación: Caracas
Mensajes: 51
Antigüedad: 15 años, 7 meses
Puntos: 0
Cargar Archivos con PHP

Buenas, necesito ayuda para poder cargar archivos utilizando php, en principio me bastaria con cargar archivos con nombres y rutas especificas del pc cliente predefinidos en el codigo por ejemplo "C:\CargarArchivo.txt" y cargarlos a su vez en una ruta especifica del servidor por ejemplo "ArchivoCargado.txt" (para ser cargado en la misma carpeta que se encuentra la pagina php).
Muchas gracias de antemano.
  #2 (permalink)  
Antiguo 28/08/2008, 09:55
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 8 meses
Puntos: 105
Respuesta: Cargar Archivos con PHP

Varon aqui te paso un codigo resencillo, y se que te va servir:

Archivo: upload.php
Código PHP:
<?php 
$status 
"";
if (
$_POST["action"] == "upload") {
    
// obtenemos los datos del archivo 
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];
    
$prefijo substr(md5(uniqid(rand())),0,6);
    
    if (
$archivo != "") {
        
// guardamos el archivo a la carpeta files
        
$destino =  "files/".$prefijo."_".$archivo;
        if (
copy($_FILES['archivo']['tmp_name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
        } else {
            
$status "Error al subir el archivo";
        }
    } else {
        
$status "Error al subir archivo";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP upload - MasterOjitos</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="413" height="40" class="titulo">PHP upload - MasterOjitos</td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione el archivo a subir:</td>
  </tr>
  <tr>
  <form action="upload.php" method="post" enctype="multipart/form-data">
    <td class="text">
      <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
      <input name="enviar" type="submit" class="boton" id="enviar" value="Upload File" />
      <input name="action" type="hidden" value="upload" />      </td>
    </form>
  </tr>
  <tr>
    <td class="text" style="color:#990000"><?php echo $status?></td>
  </tr>
  <tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos </td>
  </tr>
  <tr>
    <td class="infsub">
    <?php 
    
if ($gestor opendir('files')) {
        echo 
"<ul>";
        while (
false !== ($arch readdir($gestor))) {
           if (
$arch != "." && $arch != "..") {
               echo 
"<li><a href=\"files/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
           }
        }
        
closedir($gestor);
        echo 
"</ul>";
    }
    
?>    </td>
  </tr>
</table>
</body>
</html>
archivo estilo.css
Código HTML:
.titulo {
	font-family: "Trebuchet MS", Verdana;
	font-size: 18px;
	font-weight: bolder;
	color: #990000;
	text-decoration: none;
	border-top-width: 1px;
	border-bottom-width: 2px;
	border-top-style: solid;
	border-bottom-style: solid;
	border-top-color: #D4D0C8;
	border-bottom-color: #D4D0C8;
	text-align: left;
	padding-left: 30px;
}
.casilla {
	font-family: "Trebuchet MS", Verdana;
	font-size: 11px;
	font-weight: normal;
	color: #999999;
	text-decoration: none;
	border: 1px solid #D4D0C8;
}
.boton {
	border: 1px solid #D4D0C8;
	font-family: "Trebuchet MS", Verdana;
	font-size: 10px;
	font-weight: bold;
	color: #990000;
	text-decoration: none;
	background-color: #D4D0C8;
	vertical-align: middle;
}
.subtitulo {
	font-family: "Trebuchet MS", Verdana;
	font-size: 16px;
	font-weight: bolder;
	color: #999999;
	text-decoration: none;
	text-align: left;
	padding-left: 30px;
}
.subtitulo:hover {
	font-family: "Trebuchet MS", Verdana;
	font-size: 16px;
	font-weight: bolder;
	color: #999999;
	text-decoration: underline;
	text-align: center;
}
.subtext {
	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: normal;
	color: #999999;
	text-decoration: none;
	text-align: left;
	padding-left: 30px;
	background-color: #EFEFEF;
}
.infsub {

	font-family: "Trebuchet MS", Verdana;
	text-decoration: none;
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #D4D0C8;
}
.text {
	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: normal;
	color: #999999;
	text-decoration: none;
	text-align: left;
	padding-left: 30px;
	padding-top: 10px;
}
.link {

	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: bolder;
	color: #990000;
	text-decoration: none;
	text-align: center;
}
a.link:hover {


	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: bolder;
	color: #990000;
	text-decoration: underline;
	text-align: center;
}
li {
	list-style-type: circle;
	font-size: 16px;
	text-decoration: none;
}
.linkli {


	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: normal;
	color: #0000C0;
	text-decoration: none;
}
a.linkli:hover {



	font-family: "Trebuchet MS", Verdana;
	font-size: 12px;
	font-weight: normal;
	color: #0000C0;
	text-decoration: underline;
}
y por ultimo te creas una carpeta files.... donde se almacenaran los correos.....

espero te sirva.

Atte.

MasteerOjitos
  #3 (permalink)  
Antiguo 28/08/2008, 10:09
 
Fecha de Ingreso: agosto-2008
Ubicación: Caracas
Mensajes: 51
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Cargar Archivos con PHP

Muchas Gracias Master esto es mucho mejor a lo que pedia, ahora me pondre a analizarlo para ver si entiendo algo.
Mil gracias nuevamente
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 13:12.