Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

can´t see the image

images php coding issues or problems here.

Moderators: macek, egami, gesf

can´t see the image

Postby malpolon » Thu May 12, 2011 12:22 pm

Dear PHP-Programmer,

I have a PHP script which select randomly a image from a folder called" bilder", the script has the name sabine3.php and it is the following:

<?php

function getRandomImage($dir,$type='random')
{
global $errors,$seed;

if (is_dir($dir)) {

$fd = opendir($dir);
$images = array();

while (($part = @readdir($fd)) == true) {

if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
$images[] = $part;
}
}

// adding this in case you want to return the image array
if ($type == 'all') return $images;

if ($seed !== true) {
mt_srand ((double) microtime() * 1000000);
$seed = true;
}

$key = mt_rand (0,sizeof($images)-1);

return $dir . $images[$key];

} else {
$errors[] = $dir.' is not a directory';
return false;
}
}

$image = getRandomImage('bilder/');

echo "<img src='$image' alt='Random Image' border=\"0\">";

?>


The script is OK but I want to create a HTM-page where I can show the random image, I wrote this HTM-Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #99CC33;
}
-->
</style></head>
<body>
<img src="<? sabine3.php ?>" alt="sabine" />
</body>
</html>


But it doesn´t work, so how can I show the image???

Thank you,

frank
malpolon
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu May 12, 2011 12:14 pm

Re: can´t see the image

Postby egami » Mon May 16, 2011 8:37 am

Frank,

Your function returns a picture *IF* it's successful.
What happens when you run the php directly?

ie..
http://yoursite.com/sabine3.php ?

Ich hoffe das du nicht im Wiesau wohnst.. Ich konte mir nicht glauben das die Sabine das Ich kenne wird sich bilder auf der Internet lassen.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.