Jump to content


Photo

displaying files


  • Please log in to reply
17 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:17 PM

How do I get a .txt, .doc, .pdf file display as regular text in a webpage.
I wanted to change them all over
If pdf and doc aren't possible without using a pdf file then I just want to display txt files, any advice, using php.I know how ot access the file and url I just have to know what functions to use to get it to display
I tried
fopen
and file_get_contents
but neither of them did what I wanted.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:22 PM

as far as i know, there are two things involved here.

one is how your web server decides to serve those files.
the other is how your browser is configured to accept the files.


your web server can  be configured to send a .txt file as plaint/text and if your browser is configured to download a file with a MIME type of plain/text then that's what it will do. by the way, you can also configure your web server to serve a .txt file as audio/mp3 but it won't work as you expect...just wanted to let you know its possible.


is this what you wanted to know? i think i might have misunderstood your question.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:24 PM

I have written a script finally to handle my files, it's a display file, and I made modifications to php ht access
What I am needing to ask, is I am trying to get the contents of the file via the url, http://www.funnyemai...ploads/file.ext
in this case .txt, and .doc and .pdf
But I am just wanting to pull all the text out of those files, and throw it onto the screen.  In one giant p tag
I was hoping to do<
<p>
Work with the file and make it display
</p>
But I don't know what functions to use.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:29 PM

care to show me the file_get_contents() snippet you used? That should work for you. It's better that you use htmlspecialchars() before you stick the data in a <p> tag though.

i don't know why you want to display the raw data of a .pdf or a .doc file...you do realize that all the text will seem garbled, right?

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:31 PM

I don't know much about tihis yet
I just got past the difficulty of trying to get my barebones script set up this is what I tried
get_file_contents($urloffile);
it didn't work
I also tried
$file = fopen($urloffile);
echo "$file";

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:35 PM

ok thanks.

but please define "it didn't work"
what exactly hapenned?

can you reproduce the error message you recieved?

#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:40 PM

Nothing white screen.

Here is what I have if it helps, but I will be reposting it later in another thread, I was going to keep one massive thread later for help, but here is some of the code.
This is the page that you come to to handle viewing files, and htaccess is fixed to make this work properly.
<?php
# getLoc() grabs the current URL and parses the fake folders into variables.
function getLoc(){
	$dirname = split("/", getenv("REQUEST_URI"));
	foreach ($dirname as $var) { 
		if (($var!="BidRent")&&($var!="display")&&($var!="")){ 
			$p[] = $var; 
		} 
	}
	return $p;
}
# They are called and set here.
$pages = getLoc(); 
$folder = trim($pages[0]);
$pagename = trim($pages[1]);
$site = "http://www.funnyemailforwards.com/apex/";

$pageTitle = "Page For $page1";
mysql_connect("localhost", "####", "####")or die(mysql_error());
mysql_select_db("funnyemailforwards")or die(mysql_error());

$select = "SELECT * FROM fileinfo WHERE nameoffunny = '$pagename'";
$query = mysql_query($select);
$count = mysql_num_rows($query);
$fetch = mysql_fetch_assoc($query);
if ($count > 0){
	if(extract($fetch)) {
		$successful = true;
	}else
		$successful = false;
}else{
	echo "The file Does not Exist";
}

/*
 Ok so now that you have the basic environment set up, you want to take $page1 and search the database for the
 URINAME (which you need to insert upon data submit, URL friendly -- They need to be unique!)
 preg_match("/[.doc|.txt|.wod]{4}/i",$string)
 Once you find one, grab its ID and table its under (if the types of data are in different tables).
 Once these global variables are set you will include premade files that handle each type of data, think template
 that will auto populate the page in specific areas with that datas information from the database.
 (by global variables i mean inside those includes will all use the same variables set here).
 
 So once you figure out what type it is, grabbed its id etc the page continues to load, maybe grab the title while you
 check and the type to build $pageTitle -- since this is a gateway you need to do as such.
 
 so lets say this is a picture under aaron. $area = "picture"; $uriname = "aaron"; grab the ID or just use the unique
 uriname and grab its information. the file will parse it as a picture with its info.
 
 You may notice commented includes for header and footer, i dont know how your doing it but i usually cut the top
 and bottom of my sites off and stick them in their own files, and include on main files, this allows me to not
 have to edit a hundred files if i just need to change 1 thing at the top of the site.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo "{$nameoffunny}" ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<link href="style.css" rel="stylesheet" type="text/css" />-->
</head>
<body>
<?php
$funnyurl = $site . $funnyurl;
if (preg_match("/[.txt]{4}/i", $funnyurl)){
require_once("./includes/view_text.php");
}	
	?>
</body>
</html>

Below here is the code for viewing the txt files.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo "{$nameoffunny}" ?></title>
</head>
<?php
echo "{$funnyurl}";
$open = fopen($funnyurl, "r");
echo "{$open}";
?>
<body>
</body>
</html>
$funnyurl ends up being the full file path.
The current error messages are nothing, it just doesn't do anything.
When I try to echo it like that
I get Resource Id #5 or something
here is my db info
id   type  nameoffunny  keywords  funnyurl  entrydate  approval 
     
Those are my columns in my table fileinfo
The funnyurl for this specific file is
/uploads/dickhead.txt
then the url is
http://www.funnyemai...wards.com/apex/
when I add the strings together I get the url with whatever the file name is


------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:47 PM

you mentioned using file_get_contents()
do you have the code for that?
make sure your URL is ok. echo the URL and check if it's valid

#9 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:51 PM

http://www.funnyemai...bsitereport.txt
That is the url exactly, and when I tripled check it's exactly the samething, it will change with each file, but it will still always point to the right file.
The stuff I used with getfilecontents was the following code
$file = file_get_contents($funnyurl);
echo "$file";
That is what I used
I must have done it wrong because now it does something but nothing like what I expected.
http://www.funnyemai...m/file/dickhead
for one the report had 2 times as much in it as that, it seems, adn another it looks like crap, I thought it would print it out like it was in the txt file.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 05:53 PM

<?php
$file = file_get_contents($funnyurl);
$file = nl2br($file);
echo "$file";
?>
That worked
now how do I handle .pdf, or .doc files, or are those worthless, or overly complicated to get to work properly.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 06:19 PM

PHP can create PDF's but i'm not aware of any way in which it can read and render it.

doc's are a no go.

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 08:29 PM

I finished my txt script but I can't get my images to access for some reason, I tried the following 2 codes on the appropriate page.
echo '<img src="{$funnyurl}" />';
and
echo "<img src='{$funnyurl}' />;
and
<img src="<?php echo '{$funnyurl}'>;
I cna't get any of them to work.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 08:34 PM

Try:
<?php
echo '<img src="' . $funnyurl . '" />';
?>

Ken

#14 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 08:38 PM

It didn't work for some reason, I know it works some, because I had another one access the txt file earlier, and it worked perfectly.  But now the image isn't showing up, I have it in another page, aside from my pages up there this is what I have in my view image file, if you want to see how they get here look in the first post.  I have one php file for each grouped types
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo "{$nameoffunny}" ?></title>
</head>
<body>
<?php
echo '<img src="' . $funnyurl . '" />';
?>
</body>
</html>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#15 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 08:42 PM

When you do a "show source" with the browser, what does the generated source look like?

Ken

#16 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 08:49 PM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>testpicture</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<link href="style.css" rel="stylesheet" type="text/css" />-->
</head>
<body>
</body>
</html>
This is what I have so far, but that is with the code you gave me, I don't understand why it isn't showing up there.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#17 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 09:12 PM

I got it nevermind, thanks I had the recieving script wrong.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#18 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 05 July 2006 - 09:21 PM

<object classid="{$clsid}" type="{$type}" data="{$data}">
This is the code I have to insert my windows media player thing.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users