Page 1 of 1

include is not working

Posted: Wed Feb 23, 2011 4:31 pm
by kawakes
Hey,
First off, please know that I'm a complete noob in php and only have started recently. I'm trying to create a random image generator for my site although, I'm having one big problem. The include for the php script is not working, I have several includes in my site and they all work but this include is refusing to.

Here is the error message I'm getting. Note, I have throughly made sure there are no errors in spelling or anything that could be causing the include to fail.

Warning: include(C:\inetpub\wwwroot/includes/random_img.php) [function.include]: failed to open stream: No such file or directory in C:\inetpub\wwwroot\kawakestudios\index.php on line 1

Here is the code:

<?php include ('./includes/random_img.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1 ... tional.dtd">

Re: include is not working

Posted: Wed Feb 23, 2011 5:33 pm
by pickle
The file you're viewing, index.php, is in a subfolder called "kawakestudios". The file you're including, I'm assuming, sits in kawakestudios/include/random_img.php. As far as I can tell, your include() call should work. Since you're running Windows, I wonder if maybe the './' is causing problems. That's superfluous anyway, so take that off & see what happens.

If that doesn't work, output the result of get_cwd() in your index.php to see what directory PHP thinks its working in.

Finally, I can't imagine why you would include that file at that spot? what does random_img.php do? Does it output html code pointing to a random image? Does it act like an image itself?

Re: include is not working

Posted: Thu Feb 24, 2011 2:50 am
by kawakes
Thanks for the help. The ./ was causing the error but now it's working. The random_img.php is used to select a random image and it's caption by using a multidimensional array. The script is this:
<?php
$images = array(

array('file' => 'copyright',
'caption' => 'The copyright php script'),

array('file' => 'demo',
'caption' => 'Screen shot of Demo 10'),

array('file' => 'ship',
'caption' => 'Very early demo of the engine'),

array('file' => 'imgen',
'caption' => 'The random image generator'),
);

//image counter & Generator
$num_images = count($images);

$max = $num_images - 1;

$i = rand(0, $max); //random from 0 to max

$selected_image = "images/{$images[$i]['file']}.jpg";

$caption = $images[$i]['caption'];

if (file_exists ($selected_image) && is_readable($selected_image)) {
$image_size = getimagesize($selected_image);
}

There are some other parts that are used in the index file to set the image width for the caption.
Thanks again :)