·
miarroba.com
Abrir un fichero desde el espacio web
 
Índice de subforos · Espacio WEB · PHP
Noticias · Buscar · Tags · Tagboard · Usuarios · Fisgona
Autor Mensaje 
Discos_60Discos_60
Usuario Novato
Usuario Novato


Mensajes: 1
Desde: 02/Oct/2003
#1 ·
Abrir un fichero desde el espacio web

El siguiente codigo me permite subir un fichero a mi espacio web, pero no consigo abrirlo para almacenarlo en una BBDD.

El codigo de mi programa PHP es el siguiente:


if (move_uploaded_file($archivo, $nombre)) // Traerte el archivo a tu espacio Web
{

$fp = fopen ("nombre", "r";
$contenido = fread($fp, $tamanio);
$contenido = addslashes($contenido);
fclose($fp);
unlink($nombre);

}

Consigo subir el fichero, pero luego no consigo abrirlo.
El error que me da es el siguiente:

Warning: fopen(): Unable to access nombre in /home/webcindario/musicapoprock60/prueba/guardar_archivo.php on line 23

Warning: fopen(nombre): failed to open stream: No such file or directory in /home/webcindario/musicapoprock60/prueba/guardar_archivo.php on line 23


02/Oct/2003 13:17 GMT+1
LizethLizeth
Usuario habitual
Usuario habitual

Haz clic para ver el perfil del usuario
Mensajes: 21
Desde: 06/May/2003
#2 ·
RE: Abrir un fichero desde el espacio web

Te pongo el que uso en mi Web, bueno el que usare cuando este lista la web.

Consta de 2 archivos 1 que es el que sirve para buscar el archivo que se va a subir y otro que procesa los datos.

Archivo1(Subir.php)
************************************************
<html>
<head>
<Title>Subir Fan Fic</Title>
<script LANGUAGE="JavaScript">

extArray = new Array(".txt", ".TXT");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Se permiten únicamente archivos con la extención: "
+ (extArray.join(" ")) + "\nPor favor, seleccione otro archivo "
+ "e intente de nuevo.");
}

</script>
</head>
<body BGCOLOR="#000000" TEXT="#FFFFFF" ALINK="#FF0000" VLINK="#FF00FF" LINK="#0000FF">
<form method="post" action="subirarchivo.php" enctype="multipart/form-data" name="upform">
<input type="file" name="archivo" style="BORDER-LEFT-COLOR: #252525; BORDER-BOTTOM-COLOR: #252525; COLOR: #000000; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: #252525; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid;BORDER-RIGHT-COLOR: #252525; BORDER-BOTTOM-STYLE: solid">
<input type="button" name="Submit" value="Enviar" onclick="LimitAttach(this.form, this.form.archivo.value)" style="BORDER-LEFT-COLOR: #252525; BORDER-BOTTOM-COLOR: #252525; COLOR: #000000; BORDER-TOP-STYLE: solid; BORDER-TOP-COLOR: #252525; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid;BORDER-RIGHT-COLOR: #252525; BORDER-BOTTOM-STYLE: solid">
</form>
</body>
</html>
************************************************
Archivo2(subirarchivo.php)
************************************************
<HTML>
<HEAD>
<TITLE>Informe</TITLE>
</HEAD>
<Body BGCOLOR="#FF0000" TEXT="#FFFFFF" ALINK="#FF0000" VLINK="#FF00FF" LINK="#0000FF">
<?
if(!file_exists("fanfic/$archivo_name")) {
move_uploaded_file($archivo,"fanfic/$archivo_name") ;
echo "El archivo ha sido subido con éxito." ;
}
else{
echo "El archivo ya existe." ;
}
?>
</BODY>
</HTML>
************************************************

09/Oct/2003 07:37 GMT+1
LizethLizeth
Usuario habitual
Usuario habitual

Haz clic para ver el perfil del usuario
Mensajes: 21
Desde: 06/May/2003
#3 ·
RE: Abrir un fichero desde el espacio web

Se me olvidaba ponerte el que habre el archivo.

Te lo dare tal cual esta en mi web.

Este le el contenido del directorio(lee.php)
************************************************
<script language="JavaScript">
<!--
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
toolbar_str = toolbar ? 'yes' : 'no';
menubar_str = menubar ? 'yes' : 'no';
statusbar_str = statusbar ? 'yes' : 'no';
scrollbar_str = scrollbar ? 'yes' : 'no';
resizable_str = resizable ? 'yes' : 'no';
window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

// -->
</script>
<?php
//definimos el path de acceso
$path = "fanfic";

//abrimos el directorio
$dir = opendir($path);
//Se procede al leido del directorio
echo"<TABLE WIDTH='100%' ALIGN='LEFT'>";
while ($elemento = readdir($dir))
{
//Estos filtros evitan mostrar archivos que no sean Txt
if (substr($elemento,-4) == ".txt" || substr($elemento,-4) == ".TXT"){
echo"<TR><TD>*--></TD><TD style=\"border-width:1; border-color:red; border-style:dotted;\"><a href=\"javascript:na_open_window('win', 'mostrarfanfic.php?elemento=fanfic/$elemento', 0, 0, 400, 500, 0, 0, 0, 1, 0)\">";
echo ucfirst(substr($elemento, 0,-4));
echo"</a></TD></TR>";
}
}
echo"</TABLE>";
//Cerramos el directorio
closedir($dir);
?>
************************************************
Ultimo archivo llamado(mostrarfanfic.php)
************************************************
<html>
<head>
<Title>Fan Fic</Title>
</script>
<head>
<body BGCOLOR="#000000" TEXT="#FFFFFF" ALINK="#FF0000" VLINK="#FF00FF" LINK="#0000FF">
<center>
<?
//abre un archivo e imprime cada linea
$archivo = fopen("$elemento" , "r");
if ($archivo) {
while (!feof($archivo)) {
$linea = fgets($archivo, 255);
$linea = htmlspecialchars($linea);
echo"<font color='Yellow'> $linea</font>";
}
}
fclose ($archivo);

?><BR>
<center>
</body>
</Body>
************************************************

Te di todo el codigo para que tomes lo que te sirva de el. Hay funciones muy interesantes y utilies. Espero que todo esto te sea de utilidad. No soy buen@ en Php incluso podria a ver mucho codigo para optimizar.

09/Oct/2003 07:45 GMT+1
Índice de subforos · Espacio WEB · PHP
Temas similares
Asunto Autor#VisitasÚltima respuesta
¿Como saber el espacio web gastado mediante php?16/Dic/2005, 14:19
davigon2davigon2
238818/Dic/2005, 10:04
davigon2davigon2 Ir al último mensaje del tema
Como generar indice para Google Sitemaps en un Espacio WEB21/Jun/2005, 22:06
mrtnw2003mrtnw2003
12.37425/Jun/2005, 01:06
mrtnw2003mrtnw2003 Ir al último mensaje del tema
ME ESPACIO WEB NO TIENE UNA PAG. D INICIO..15/Feb/2005, 04:57
kumbiasafullkumbiasafull
231215/Feb/2005, 05:16
Torry_IITorry_II Ir al último mensaje del tema
No me funciona bien la pagina php en el Espacio Web05/Nov/2004, 01:02
patinador-zgzpatinador-zgz
335906/Nov/2004, 02:03
Atomo64Atomo64 Ir al último mensaje del tema
Deu erro no espacio web e agora?05/Jul/2004, 02:29
julianorrjulianorr
0271No hay respuestas
Opciones:
Versión imprimible del tema
Subscríbete a este tema
Date de baja de este tema
Ir al subforo:  

TU NO PUEDES Escribir nuevos temas en este foro
TU NO PUEDES Responder a los temas en este foro
TU NO PUEDES Editar tus propios mensajes en este foro
TU NO PUEDES Borrar tus propios mensajes en este foro
Todas las fechas y horas son GMT+1. Ahora son las 06:37
Miarroba Networks, S.L. C/ 18 de Julio, 21 Bajo, 39610 Astillero (CANTABRIA) - CIF B-39512736
Inscrita en el Registro Mercantil de Cantabria, tomo 743, folio 161, libro 0, hoja S-12428, Instripción 1ª