PHPorbust Posted October 15, 2010 Share Posted October 15, 2010 Hi, I wrote this to retrieve a file based on a POST value. For some reason it will not retrieve the file content and display it at all. I get this message: Warning: fopen(18.txt) [function.fopen]: failed to open stream: No such file or directory in /home/content/x/y/z/path/html/includes/different.php The 18 is the correct POST value. So that is a positive There is a file named 18.txt in /home/content/x/y/z/path/html/includes/18.txt Thanks. <?php $id5 = $_POST[id]; //Display Text File $myFile = $id5; $myFile .= ".txt"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; ?> Link to comment https://forums.phpfreaks.com/topic/215904-php-calling-a-txt-file-from-post-variable/ Share on other sites More sharing options...
ZachMEdwards Posted October 15, 2010 Share Posted October 15, 2010 file_get_contents echo file_get_contents($_POST['id'].'.txt'); Link to comment https://forums.phpfreaks.com/topic/215904-php-calling-a-txt-file-from-post-variable/#findComment-1122370 Share on other sites More sharing options...
PHPorbust Posted October 15, 2010 Author Share Posted October 15, 2010 Your code is nicer And it appears my code actually works too! I actually did have the .txt files in the wrong directory. I must have staired at it for hours not noticing. Doooh! Thanks Zach for optimizing! Link to comment https://forums.phpfreaks.com/topic/215904-php-calling-a-txt-file-from-post-variable/#findComment-1122381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.