graham23s Posted May 16, 2007 Share Posted May 16, 2007 Hi Guys, when a user uploads to my site they can upload doc files and i store the doc files in a docs folder and store: file.doc in the database, when i try to read the file it only displays the filename and not the content here my code: $filename = "docs/$docs"; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize($filename)); fclose ($fd); echo $doc; amy help would be appreciated Graham Quote Link to comment https://forums.phpfreaks.com/topic/51621-solved-reading-files-stored-in-mysql/ Share on other sites More sharing options...
nikkieijpen Posted May 16, 2007 Share Posted May 16, 2007 $fd = fopen($filename, 'r') or die("Can't Open File"); $contents = fgets($fd); fclose($fd); echo $contents; Quote Link to comment https://forums.phpfreaks.com/topic/51621-solved-reading-files-stored-in-mysql/#findComment-254310 Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 You can simply use file_get_contents()... Orio. Quote Link to comment https://forums.phpfreaks.com/topic/51621-solved-reading-files-stored-in-mysql/#findComment-254320 Share on other sites More sharing options...
graham23s Posted May 16, 2007 Author Share Posted May 16, 2007 Hi Mate, heres my code: $query = "SELECT * FROM `nfos` WHERE `id`='$id'"; $result = mysql_query($query) or die (mysql_error()); $row = mysql_fetch_array($result) or die (mysql_error()); // get the nfo file...////////////////////////////////////////////////////////////// $nfo = $row['nfo']; //$filename = "nfos/$nfo"; // This is at root of the file using this script. //$fd = fopen ($filename, "r"); // opening the file in read mode. //$contents = fread ($fd, filesize($filename)); // reading the content of the file. //fclose ($fd); $fd = fopen($nfo, "are") or die ("Can't Open File"); $contents = fgets($fd); fclose($fd); echo $contents; //echo $nfo; echo "<br /><br />"; i have tried .nfo and .doc files they both seem to ech out the name of the file rather than the contents, is it maybe my coding? Graham cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/51621-solved-reading-files-stored-in-mysql/#findComment-254338 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.