Jump to content

file not reading nor outputing?


$php_mysql$

Recommended Posts

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

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

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.