$php_mysql$ Posted January 25, 2011 Share Posted January 25, 2011 hi i tried to add this to my php file <?php $xfile = @file('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $data = explode("::",$xfile[$random_num]); echo $data[1]; ?> i get no output i then tried just including the txt file like include 'banners.txt'; then everything in the txt file opens. and if i use fopen like this <?php $xfile = fopen ('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $udata = explode("::",$xfile[$random_num]); echo $udata[1]; ?> i get this error Warning: fopen(banners.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/public_html/template/folder1/main.php on line 72 where as the txt file exist there anyone could help solve my issue? Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/ Share on other sites More sharing options...
litebearer Posted January 25, 2011 Share Posted January 25, 2011 Let's start with, what is the structure (content) of banners.txt? Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1164936 Share on other sites More sharing options...
codefossa Posted January 25, 2011 Share Posted January 25, 2011 If you're just reading why not file_get_contents() or curl_exec() Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1164941 Share on other sites More sharing options...
litebearer Posted January 25, 2011 Share Posted January 25, 2011 try... <?php $file = "banners.txt"; $lines = file($file); $random_num = rand (0,count($lines)-1); $data = explode("::",$lines[$random_num]); echo $data[0] . "<br>"; echo $data[1]; ?> Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1164942 Share on other sites More sharing options...
$php_mysql$ Posted January 26, 2011 Author Share Posted January 26, 2011 try... <?php $file = "banners.txt"; $lines = file($file); $random_num = rand (0,count($lines)-1); $data = explode("::",$lines[$random_num]); echo $data[0] . "<br>"; echo $data[1]; ?> hey mate, tried u bit of codes but neh same thing i get this error message Warning: file(banners.txt) [function.file]: failed to open stream: No such file or directory in /home/www/public_html/template/file1.php on line 74 Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165403 Share on other sites More sharing options...
litebearer Posted January 26, 2011 Share Posted January 26, 2011 maybe start with this <?php $filename = '/pathto/filename_here'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?> Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165405 Share on other sites More sharing options...
$php_mysql$ Posted January 27, 2011 Author Share Posted January 27, 2011 still didn work, still get the same old file does not exist error message. by any means do you think something is disabled in the server which is causing it to not fetch the file? only include function works rest nothing working Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165884 Share on other sites More sharing options...
spaceman12 Posted January 27, 2011 Share Posted January 27, 2011 <?php $getFILE=file_get_contents('banners.txt'); $arrFILE=explode("::", $getFILE); $shuffleFILE=mt_rand(0,count($arrFILE)-1); echo $arrFILE[$shuffleFILE]; ?> Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165895 Share on other sites More sharing options...
$php_mysql$ Posted January 27, 2011 Author Share Posted January 27, 2011 this is what i get Warning: file_get_contents(banners.txt) [function.file-get-contents]: failed to open stream: No such file or directory in /home/www/public_html/template/file1.php on line 80 Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165899 Share on other sites More sharing options...
spaceman12 Posted January 27, 2011 Share Posted January 27, 2011 keep banner.txt on the same folder as the php file. Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165917 Share on other sites More sharing options...
litebearer Posted January 27, 2011 Share Posted January 27, 2011 My suspicion is that your path is wrong. what does you folder tree structure look like? Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1165965 Share on other sites More sharing options...
$php_mysql$ Posted January 27, 2011 Author Share Posted January 27, 2011 yes it is in that folder itself mate. as i said if i do it like include("banners.txt"); it shows everything in the txt file. only include is working dunno why others say file does not exist :-( Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1166061 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 have you tried renaming the file or using a different file and filename? any chance there is a space before or after the file name? Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1166080 Share on other sites More sharing options...
$php_mysql$ Posted January 27, 2011 Author Share Posted January 27, 2011 mate i tried to rename it to banners.php and so so even changing extn and name not helping. im hating this. what else could we do with the include function to randomize things? for include is fetching the file without any error. Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1166109 Share on other sites More sharing options...
litebearer Posted January 27, 2011 Share Posted January 27, 2011 for the moment let's forget about randomizing. Let's first concentrate on simply opening the file... $file = "CURRENT NAME OF THE FILE"; $content = file_get_contents($file); echo $content; Link to comment https://forums.phpfreaks.com/topic/225607-file-not-reading-nor-outputing/#findComment-1166132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.