Jump to content

Recommended Posts

hi, I'm trying to open "local" files with the following script. I'm trying to access the files remotely though and this script works up until the file get contents portion. now file_get_contents() itself is working, it will take the homepage and other remote pages but for some reason this page:

http://ci.durham.nh.us/government/Agendas/historic district commission/2009/hist06042009.html and others like it won't work?

 

I don't know what the problem is but I have a feeling it has to do with IIS. Could permissions be affecting this?

<?php
function get_tables()
{
$host="xx.x.xx.xxx";
$user="xxxx";
$password="xxxx";

mysql_connect($host,$user,$password);
mysql_select_db("agendas");
$rows = mysql_query("SHOW TABLES");

while ($row = mysql_fetch_array($rows))
{
	$group = $row[0];
	if ($group != "users")
	{
	echo "<h2><u>".$group."</u></h2><br>";
	listsend($group);
	}
}
}

function listsend($group)
{
  $query = "SELECT * FROM `".$group."`";
  $result = mysql_query($query);
          for ($i = 0; $i < mysql_num_rows($result); $i++)
          {
            $row = mysql_fetch_row($result); 
		 $upload = $row[0];
		 $date = $row[1];
		 $Location = $row[2];
		 $docloc = $row[3];
		 $Time = $row[4];
		 uploader($upload, $date, $Location, $docloc, $Time);
          }
}

function uploader($upload, $date, $Location, $docloca, $Time)
{
	$FileName = "http://ci.durham.nh.us/government/".$docloca;
	echo $FileName."<br>";
	$ev_id= mysql_insert_id();
	$icsid="1";
	//******SEE IF FILE EXISTS, GET CONTENTS********//
	if (file_exists($FileName))
		{
		$description= file_get_contents($FileName);
		echo $description."<br>";
		}
	else 
		{
		echo "ERROR<br>";
		}
	//*******************END IF********************//
	//...MORE MYSQL dAtABASE INSERTING SCRIPT...
}

get_tables();
?>

And the error is probably

 

<br />

<b>Warning</b>:  file_get_contents(http://ci.durham.nh.us/government/Agendas/historic district commission/2009/hist06042009.html) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

 

 

basically a space isn't a valid part of a URL.. so your need to replace the space with a %20

<?php
$url = "http://ci.durham.nh.us/government/Agendas/historic district commission/2009/hist06042009.html";
$url = str_replace(" ","%20",$url);
echo file_get_contents($url);
?>

 

your could also try encoding it all,

 

here's draft (probably wrong)

<?php
$url = "http://ci.durham.nh.us/government/Agendas/historic district commission/2009/hist06042009.html";
$url = str_replace("%3A",":",implode("/",array_map("rawurlencode",explode("/",$url))));
echo file_get_contents($url);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.