Discos_60 Usuario Novato

Mensajes: 1 Desde: 02/Oct/2003 | Abrir un fichero desde el espacio webEl 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 | |
Lizeth Usuario habitual

 Mensajes: 21 Desde: 06/May/2003 | RE: Abrir un fichero desde el espacio webTe 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 | |
Lizeth Usuario habitual

 Mensajes: 21 Desde: 06/May/2003 | RE: Abrir un fichero desde el espacio webSe 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 | |