Re: Include file error, common one I think

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> escreveu na mensagem 
>> news:8316202.post@xxxxxxxxxxxxxxxxxx
>>> 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
>>
>>
>>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux