Jump to content

[SOLVED] Reading files stored in mysql


graham23s

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51621-solved-reading-files-stored-in-mysql/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.