Ninjakreborn Posted July 5, 2006 Share Posted July 5, 2006 How do I get a .txt, .doc, .pdf file display as regular text in a webpage.I wanted to change them all overIf 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 displayI triedfopenand file_get_contentsbut neither of them did what I wanted. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/ Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53434 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 I have written a script finally to handle my files, it's a display file, and I made modifications to php ht accessWhat I am needing to ask, is I am trying to get the contents of the file via the url, http://www.funnyemailforwards.com/apex/uploads/file.extin this case .txt, and .doc and .pdfBut I am just wanting to pull all the text out of those files, and throw it onto the screen. In one giant p tagI was hoping to do<<p>Work with the file and make it display</p>But I don't know what functions to use. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53435 Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53441 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 I don't know much about tihis yetI just got past the difficulty of trying to get my barebones script set up this is what I triedget_file_contents($urloffile);it didn't workI also tried $file = fopen($urloffile);echo "$file"; Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53442 Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 ok thanks.but please define "it didn't work"what exactly hapenned?can you reproduce the error message you recieved? Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53444 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 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.[code]<?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>[/code]Below here is the code for viewing the txt files.[code]<!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><?phpecho "{$funnyurl}";$open = fopen($funnyurl, "r");echo "{$open}";?><body></body></html>[/code]$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 thatI get Resource Id #5 or somethinghere is my db infoid type nameoffunny keywords funnyurl entrydate approval Those are my columns in my table fileinfoThe funnyurl for this specific file is /uploads/dickhead.txtthen the url ishttp://www.funnyemailforwards.com/apex/when I add the strings together I get the url with whatever the file name is Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53447 Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53456 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 http://www.funnyemailforwards.com/apex/uploads/websitereport.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[code]$file = file_get_contents($funnyurl);echo "$file";[/code]That is what I usedI must have done it wrong because now it does something but nothing like what I expected.http://www.funnyemailforwards.com/file/dickheadfor 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. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53458 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 [code]<?php$file = file_get_contents($funnyurl);$file = nl2br($file);echo "$file";?>[/code]That workednow how do I handle .pdf, or .doc files, or are those worthless, or overly complicated to get to work properly. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53460 Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53476 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 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}" />';andecho "<img src='{$funnyurl}' />;and<img src="<?php echo '{$funnyurl}'>;I cna't get any of them to work. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53557 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 Try:[code]<?phpecho '<img src="' . $funnyurl . '" />';?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53559 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 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[code]<!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><?phpecho '<img src="' . $funnyurl . '" />';?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53561 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 When you do a "show source" with the browser, what does the generated source look like?Ken Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53565 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 [code]<!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>[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53568 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 I got it nevermind, thanks I had the recieving script wrong. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53588 Share on other sites More sharing options...
Ninjakreborn Posted July 5, 2006 Author Share Posted July 5, 2006 [code]<object classid="{$clsid}" type="{$type}" data="{$data}">[/code]This is the code I have to insert my windows media player thing. Quote Link to comment https://forums.phpfreaks.com/topic/13754-displaying-files/#findComment-53591 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.