Author Topic: Display content of a HTML file  (Read 2426 times)

0 Members and 1 Guest are viewing this topic.

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Display content of a HTML file
« on: December 17, 2009, 08:12:10 AM »
hey... ;D

I have a postgreSQL database which contains URL's to HTML documents. I want to output the contents of this document on a particular page on my site. so far i have tried 'file_get_contents', 'include' and 'fopen' but dont seem to be getting anywhere. The code i am using is

 
Code: [Select]
<?php
            $sql
="select * from jfs where issue = (select max(issue) from jfs) and format = 'html'";// selects the latest issue


            
$result_set pg_Exec ($conn$sql);
            
$rows pg_NumRows($result_set);

            if ((!
$result_set) || ($rows 1)) {
                  echo 
"<H1>ERROR - no rows returned</H1><P>";
                  exit;  
//exit the script
                  
}

            for (
$j=0$j $rows$j++)
               {
               
$issue pg_result($result_set$j"issue");
               
$page pg_result($result_set$j"page");
               
$author pg_result($result_set$j"author");
               
$title pg_result($result_set$j"title");
               
$format pg_result($result_set$j"format");
               
$url pg_result($result_set$j"url");   

//$url="http://google.co.uk/";
//$home=readfile($url);
include ("$url");
//echo $home;



               }
?>

 
<?php
        pg_FreeResult
($result_set);
        
pg_Close($conn);
?>


i know that my query my working as i am able to echo the url but cannot display the contents of the file

any help would be greatley appreciated

el nino

Offline rajivgonsalves

  • Addict
  • Posts: 2,160
  • Gender: Male
  • Whizzkid
    • View Profile
    • My Personal Website
Re: Display content of a HTML file
« Reply #1 on: December 17, 2009, 08:19:39 AM »
what does the url looks like? is it on your own server or  from some other server, if its on your server is it absolute paths or just relative ?
Cheers!
Rajiv

Code: [Select]
// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Display content of a HTML file
« Reply #2 on: December 17, 2009, 08:24:55 AM »
the url is on another server, it currently looks like:

http://www.comp.brad.ac.uk/intranet/modules/DWT/jfs/formats.html

Offline rajivgonsalves

  • Addict
  • Posts: 2,160
  • Gender: Male
  • Whizzkid
    • View Profile
    • My Personal Website
Re: Display content of a HTML file
« Reply #3 on: December 17, 2009, 08:27:42 AM »
this

Code: [Select]
include ("$url");
should be

Code: [Select]
echo file_get_contents($url);;

the reason its not showing up the url is not found.
Cheers!
Rajiv

Code: [Select]
// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Display content of a HTML file
« Reply #4 on: December 17, 2009, 08:33:53 AM »
I tried

Code: [Select]
echo file_get_contents($url);
as well as replacing $url with the actual url but i'm still not getting any results.

Offline rajivgonsalves

  • Addict
  • Posts: 2,160
  • Gender: Male
  • Whizzkid
    • View Profile
    • My Personal Website
Re: Display content of a HTML file
« Reply #5 on: December 17, 2009, 08:36:51 AM »
put these lines at the very beginning of your script and see if you get any errors/notices
Code: [Select]
ini_set('display_errors', '1');
error_reporating(E_ALL);
Cheers!
Rajiv

Code: [Select]
// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Display content of a HTML file
« Reply #6 on: December 17, 2009, 08:43:03 AM »
thanks for that...ok so i now get the following error

Warning: file_get_contents(http://www.comp.brad.ac.uk/intranet/modules/DWT/jfs/formats.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in *file location* on line 54

line 54 is:
Code: [Select]
echo file_get_contents($url);

Offline rajivgonsalves

  • Addict
  • Posts: 2,160
  • Gender: Male
  • Whizzkid
    • View Profile
    • My Personal Website
Re: Display content of a HTML file
« Reply #7 on: December 17, 2009, 08:44:42 AM »
Yes that url is invalid and does not exists.
Cheers!
Rajiv

Code: [Select]
// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Display content of a HTML file
« Reply #8 on: December 17, 2009, 08:45:51 AM »
it must do because if i enter the url into my address bar i can see the page

Offline getmizanur

  • Irregular
  • Posts: 8
    • View Profile
Re: Display content of a HTML file
« Reply #9 on: December 27, 2009, 03:10:47 AM »
it must do because if i enter the url into my address bar i can see the page

you need user name and password to access page.

if you can view the page through address bar then you can be able to fetch the content.

Offline el_ninoTopic starter

  • Irregular
  • Posts: 28
    • View Profile
Re: Display content of a HTML file
« Reply #10 on: December 27, 2009, 08:46:17 AM »
problem solved... seemed to be issues with the servers at uni