aschulz90 Posted June 15, 2009 Share Posted June 15, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162249-solved-file_get_contents-not-working-for-some-files/ Share on other sites More sharing options...
MadTechie Posted June 15, 2009 Share Posted June 15, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162249-solved-file_get_contents-not-working-for-some-files/#findComment-856297 Share on other sites More sharing options...
aschulz90 Posted June 15, 2009 Author Share Posted June 15, 2009 Thanks I figured it out right before you told me because it seemed so weird that ones in a folder called dcat were working but others weren't then I realized, the space was the difference. Quote Link to comment https://forums.phpfreaks.com/topic/162249-solved-file_get_contents-not-working-for-some-files/#findComment-856303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.