Foros del Web » Programando para Internet » PHP »

error en file_get_contents

Estas en el tema de error en file_get_contents en el foro de PHP en Foros del Web. Tengo un formualrio donde le indico que escriba la pagina web. Éste debe ir a calcular velocidad y otros dados en un PHP, pero me ...
  #1 (permalink)  
Antiguo 01/05/2011, 11:45
 
Fecha de Ingreso: septiembre-2010
Mensajes: 72
Antigüedad: 13 años, 7 meses
Puntos: 0
error en file_get_contents

Tengo un formualrio donde le indico que escriba la pagina web. Éste debe ir a calcular velocidad y otros dados en un PHP, pero me da un error:
Warning: file_get_contents($direccion) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\Integra2_1\veloc_descarga.php on line 15

Lo que tengo es:
FORMULario
<html>
<head><title> velocidad </title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #669900;
}
.Estilo1 {
color: #CC0033;
font-weight: bold;
}
-->
</style></head>
<body>
<center><h1><strong> </strong></h1>
<h2>MENU VELOCIDAD DESCARGA WEBS </h2>
<p>&nbsp;</p>
<table width="84%" border="2" cellspacing="1" cellpadding="5">
<tr>
<td width="36%" height="57"><div align="center">INTRODUCCION NOMBRE P&Aacute;GINA </div></td>
<td width="64%"><form name="form1" method="post" action="veloc_descarga.php">
<p>Nombre de la p&aacute;gina WEB
<input type="text" name="url" >
escriba asi http://www.google.com
</p>
<p>
<input type="submit" name="Submit" value="Enviar">
</p>
<p>&nbsp; </p>
</form></td>
</tr>
<tr>
<td height="64">ESTADISTICAS</td>
<td>&nbsp;</td>
</tr>
</table>
<h1 class="Estilo1">&nbsp;</h1>
<p class="Estilo1">&nbsp;</p>
<p class="Estilo1">&nbsp;</p>
<p class="Estilo1">&nbsp;</p>
<hr>

<p> <br>

<p>&nbsp;</p>
</form>
</center>
</body>
</html>

script

$direccion=$_REQUEST['url'];

if($direccion){
echo "$direccion";
//Veloc (bits / segundo) = bits / (TFin - TComienzo)
//carácter CUALQUIERA siempre tendrá un tamaño de 1 Byte, es decir 8 impulsos electrónicos ( 8 Bit)
$tmicro[1]= microtime();
$q_espacios = explode(" ",$tmicro[1]);
$tiempo_[1]= $q_espacios[1]+$q_espacios[0];

//file_get_contents — Transmite un archivo entero a una cadena
$pagina=file_get_contents('$direccion');
$tamanoKB= strlen($pagina)/1024;
//for ($i=0;$i<$tamanoKB;$i++){
//for ($i=0;$i<srtlen($pagina);$i++){
//$line = fget($pagina);
//}
//$tamanoKB= strlen($pagina)/1024;

echo $tamanoKB ."<br>";

$tiempo_micro[2] = microtime();
$q_espacios= explode(" ",$t_micro[2]);
$tiempo_[2] =$q_espacios[1] + $q_espacios[0];
$timeutilizado = number_format(($tiempo_[2] - $tiempo_[1]),2, "." ,","); //Format a number with grouped thousands

$velocdescarga= round($tamanoKB/$timeutilizado,3);

echo 'velocidad de conexión es de: '.$velocdescarga.' Kbps <br /> Se enviarón:'.$tamanoKB.
' Kb, Tiempo utilizado: '.$timeutilizado.' Segundos <hr>';
}
?>
  #2 (permalink)  
Antiguo 01/05/2011, 12:04
Avatar de fekaa11  
Fecha de Ingreso: abril-2011
Ubicación: Córdoba / Argentina
Mensajes: 115
Antigüedad: 13 años
Puntos: 34
Respuesta: error en file_get_contents

Estuve haciendo pruebas para ver donde estaba el error.

Cambia $_REQUEST['url']; por $_POST['url'];; verás que el error desaparece. Código completo:

HTML :
Código HTML:
Ver original
  1. <head><title> velocidad </title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  2. <!--
  3. body {
  4. background-color: #669900;
  5. }
  6. .Estilo1 {
  7. color: #CC0033;
  8. font-weight: bold;
  9. }
  10. -->
  11. </style></head>
  12. <center><h1><strong> </strong></h1>
  13. <h2>MENU VELOCIDAD DESCARGA WEBS </h2>
  14. <p>&nbsp;</p>
  15. <table width="84%" border="2" cellspacing="1" cellpadding="5">
  16. <tr>
  17. <td width="36%" height="57"><div align="center">INTRODUCCION NOMBRE P&Aacute;GINA </div></td>
  18. <td width="64%">
  19. <form name="form1" method="post" action="veloc_descarga.php">
  20. <p>Nombre de la p&aacute;gina WEB
  21. <input type="text" name="url" >
  22. escriba asi http://www.google.com
  23. </p>
  24. <p>
  25. <input type="submit" name="Submit" value="Enviar">
  26. </p>
  27. <p>&nbsp; </p>
  28. </form></td>
  29. </tr>
  30. <tr>
  31. <td height="64">ESTADISTICAS</td>
  32. <td>&nbsp;</td>
  33. </tr>
  34. <h1 class="Estilo1">&nbsp;</h1>
  35. <p class="Estilo1">&nbsp;</p>
  36. <p class="Estilo1">&nbsp;</p>
  37. <p class="Estilo1">&nbsp;</p>
  38. <hr>
  39. </center>
  40. </body>
  41. </html>

PHP:

Código PHP:
Ver original
  1. <?php
  2. $direccion=$_POST['url'];
  3.  
  4. if($direccion){
  5. echo $direccion;
  6. //Veloc (bits / segundo) = bits / (TFin - TComienzo)
  7. //carácter CUALQUIERA siempre tendrá un tamaño de 1 Byte, es decir 8 impulsos electrónicos ( 8 Bit)
  8. $tmicro[1]= microtime();
  9. $q_espacios = explode(" ",$tmicro[1]);
  10. $tiempo_[1]= $q_espacios[1]+$q_espacios[0];
  11.  
  12. //file_get_contents — Transmite un archivo entero a una cadena
  13. $pagina=file_get_contents($direccion);
  14. $tamanoKB= strlen($pagina)/1024;
  15. //for ($i=0;$i<$tamanoKB;$i++){
  16. //for ($i=0;$i<srtlen($pagina);$i++){
  17. //$line = fget($pagina);
  18. //}
  19. //$tamanoKB= strlen($pagina)/1024;
  20.  
  21. echo $tamanoKB ."<br>";
  22.  
  23. $tiempo_micro[2] = microtime();
  24. $q_espacios= explode(" ",$t_micro[2]);
  25. $tiempo_[2] =$q_espacios[1] + $q_espacios[0];
  26. $timeutilizado = number_format(($tiempo_[2] - $tiempo_[1]),2, "." ,","); //Format a number with grouped thousands
  27.  
  28. $velocdescarga= round($tamanoKB/$timeutilizado,3);
  29.  
  30. echo 'velocidad de conexión es de: '.$velocdescarga.' Kbps <br /> Se enviarón:'.$tamanoKB.
  31. ' Kb, Tiempo utilizado: '.$timeutilizado.' Segundos <hr>';
  32. }
  33. ?>

Saludos !
__________________
Pedir perdón es de hombres inteligentes. Perdonar es de sabios.
  #3 (permalink)  
Antiguo 01/05/2011, 22:37
 
Fecha de Ingreso: septiembre-2010
Mensajes: 72
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: error en file_get_contents

Gracias.
Seguiré con el resto y si algo falla volveré a preguntar

Etiquetas: Ninguno
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 11:00.