Re: Include file error, common one I think

From: Date: Sat, 13 Jan 2007 19:12:38 +0000
Subject: Re: Include file error, common one I think
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-247042@lists.php.net to get a copy of this message
Chris Carter wrote: > Hi, > > I have used this file in my index file. When I run this file separately it > shows the random image but not when I include on my index.php. your image script shouldn't be included in your [index] page. instead it should be referenced by the src attribute of an img tag that your [index] page outputs e.g. in your [index] page have a line something like: echo '<img src="/randomimage.php" alt="" />'; > > Thanks in advance, > > > João Cândido de Souza Neto wrote: >> Is it the whole code of your file, or is there any other html code? >> >> "Chris Carter" <chandan9sharma@yahoo.com> escreveu na mensagem >> news:8316202.post@talk.nabble.com... >>> Hi, >>> >>> Here is code that I got from the internet for random image. This file >>> works >>> perfect if I try it independently but not on any existing file. I think >>> the >>> error that I am getting is quite common on the net but its new for me. >>> >>> I am getting this error: >>> >>> Warning: Cannot modify header information - headers already sent by >>> (output >>> started at /folder/test.php:12) in /folder/randomimage.php on line 19 >>> >>> the code that I got from net: >>> >>> <? >>> $folder = 'images/'; >>> $exts = 'jpg jpeg png gif'; >>> $files = array(); $i = -1; >>> if ('' == $folder) $folder = './'; >>> $handle = opendir($folder); >>> $exts = explode(' ', $exts); >>> while (false !== ($file = readdir($handle))) { >>> foreach($exts as $ext) { >>> if (preg_match('/\.'.$ext.'$/i', $file, $test)) { >>> $files[] = $file; >>> ++$i; >>> } >>> } >>> } >>> closedir($handle); >>> mt_srand((double)microtime()*1000000); >>> $rand = mt_rand(0, $i); >>> >>> >>> Line 19 is below: >>> >>> header('Location: '.$folder.$files[$rand]); >>> ?> >>> >>> Thanks a bunch. >>> Chris >>> -- >>> View this message in context: >>> >>> http://www.nabble.com/Include-file-error%2C-common-one-I-think-tf2971907.html#a8316202 >>> Sent from the PHP - General mailing list archive at Nabble.com. >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >

« previous php.general (#247042) next »