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">
include is not working
Moderator: General Moderators
Re: include is not working
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?
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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: include is not working
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
<?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