PHP Image by Default

Greetings,

I need some help on revising a simple PHP script. The script
I currently have is:

<?php
$image = getRandomImage(LL/');
echo "<img src='$image' height=90 width=120 alt='LL'>";
?>

The script looks in the subdirectory for a random image and
displays the one it chooses.

What I want to do modify it for is so that if it doesn't find
an image in the subdirectory, that a default image (from the current
directory rather than the designated subdirectory) ) can be displayed
instead.

Any suggestions?

Regards,



Fred
Fred Atkinson [ Mo, 27 August 2007 03:36 ] [ ID #1806266 ]

Re: PHP Image by Default

> I need some help on revising a simple PHP script. The script
> I currently have is:
>
> <?php
> $image = getRandomImage(LL/');
> echo "<img src='$image' height=90 width=120 alt='LL'>";
> ?>
>
> The script looks in the subdirectory for a random image and
> displays the one it chooses.
>
> What I want to do modify it for is so that if it doesn't find
> an image in the subdirectory, that a default image (from the current
> directory rather than the designated subdirectory) ) can be displayed
> instead.

and what does getRandomImage return if not image is found, does it return
null, does it return an empty string etc.

Once you find that out you simply do an if statement checking checking if it
returned null or an empty string (or whatever else it may return)
Peter [ Mo, 27 August 2007 04:22 ] [ ID #1806267 ]

Re: PHP Image by Default

On Mon, 27 Aug 2007 03:22:44 +0100, "peter" <submit [at] flexiwebhost.com>
wrote:

>
>> I need some help on revising a simple PHP script. The script
>> I currently have is:
>>
>> <?php
>> $image = getRandomImage(LL/');
>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>> ?>
>>
>> The script looks in the subdirectory for a random image and
>> displays the one it chooses.
>>
>> What I want to do modify it for is so that if it doesn't find
>> an image in the subdirectory, that a default image (from the current
>> directory rather than the designated subdirectory) ) can be displayed
>> instead.
>
>and what does getRandomImage return if not image is found, does it return
>null, does it return an empty string etc.
>
>Once you find that out you simply do an if statement checking checking if it
>returned null or an empty string (or whatever else it may return)
>

It returns null, which brings up a blank image.



Fred
Fred Atkinson [ Di, 28 August 2007 05:21 ] [ ID #1807061 ]

Re: PHP Image by Default

> It returns null, which brings up a blank image.

then you can simply do something such as:-

<?PHP
$image = getRandomImage('LL/');
if (is_null($image))
{
$image = '';// Set to the image you wish
}
echo "<img src='$image' height=90 width=120 alt='LL'>";
?>

in the if statement place the path and name of the image you want to use as
the image that will be displayed if nothing is returned from the function.
Peter [ Di, 28 August 2007 17:17 ] [ ID #1807067 ]

Re: PHP Image by Default

On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit [at] flexiwebhost.com>
wrote:

>
>> It returns null, which brings up a blank image.
>
>then you can simply do something such as:-
>
><?PHP
>$image = getRandomImage('LL/');
>if (is_null($image))
>{
> $image = '';// Set to the image you wish
>}
>echo "<img src='$image' height=90 width=120 alt='LL'>";
>?>
>
>in the if statement place the path and name of the image you want to use as
>the image that will be displayed if nothing is returned from the function.
>

When I use this:

<?php
$image = getRandomImage('LL/');
if (is_null($image))
{
$image = 'none.jpg';// Set to the image you wish
}
echo "<img src='$image' height=90 width=120 alt='LL'>";
?>

and pull up the Web page I look at the source and I see this:
<img src='' height=90 width=120 alt='LL'>

As you can see the 'none.jpg' default file is not coded into
the resulting HTML.

Any idea why?

Regards,



Fred
Fred Atkinson [ Do, 30 August 2007 06:09 ] [ ID #1808905 ]

Re: PHP Image by Default

Fred Atkinson wrote:
> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit [at] flexiwebhost.com>
> wrote:
>
>>> It returns null, which brings up a blank image.
>> then you can simply do something such as:-
>>
>> <?PHP
>> $image = getRandomImage('LL/');
>> if (is_null($image))
>> {
>> $image = '';// Set to the image you wish
>> }
>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>> ?>
>>
>> in the if statement place the path and name of the image you want to use as
>> the image that will be displayed if nothing is returned from the function.
>>
>
> When I use this:
>
> <?php
> $image = getRandomImage('LL/');
> if (is_null($image))
> {
> $image = 'none.jpg';// Set to the image you wish
> }
> echo "<img src='$image' height=90 width=120 alt='LL'>";
> ?>
>
> and pull up the Web page I look at the source and I see this:
> <img src='' height=90 width=120 alt='LL'>
>
> As you can see the 'none.jpg' default file is not coded into
> the resulting HTML.
>
> Any idea why?
>
> Regards,
>
>
>
> Fred
>

Because it's returning an empty string - which is NOT the same as null.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Do, 30 August 2007 06:14 ] [ ID #1808906 ]

Re: PHP Image by Default

On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle
<jstucklex [at] attglobal.net> wrote:

>Fred Atkinson wrote:
>> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit [at] flexiwebhost.com>
>> wrote:
>>
>>>> It returns null, which brings up a blank image.
>>> then you can simply do something such as:-
>>>
>>> <?PHP
>>> $image = getRandomImage('LL/');
>>> if (is_null($image))
>>> {
>>> $image = '';// Set to the image you wish
>>> }
>>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>>> ?>
>>>
>>> in the if statement place the path and name of the image you want to use as
>>> the image that will be displayed if nothing is returned from the function.
>>>
>>
>> When I use this:
>>
>> <?php
>> $image = getRandomImage('LL/');
>> if (is_null($image))
>> {
>> $image = 'none.jpg';// Set to the image you wish
>> }
>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>> ?>
>>
>> and pull up the Web page I look at the source and I see this:
>> <img src='' height=90 width=120 alt='LL'>
>>
>> As you can see the 'none.jpg' default file is not coded into
>> the resulting HTML.
>>
>> Any idea why?
>>
>> Regards,
>>
>>
>>
>> Fred
>>
>
>Because it's returning an empty string - which is NOT the same as null.

As you can see, I am defining the string as none.jpg. I can't
imagine why it still thinks it is null.




Fred
Fred Atkinson [ Fr, 31 August 2007 03:31 ] [ ID #1809829 ]

Re: PHP Image by Default

Fred Atkinson wrote:
> On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle
> <jstucklex [at] attglobal.net> wrote:
>
>> Fred Atkinson wrote:
>>> On Tue, 28 Aug 2007 16:17:09 +0100, "peter" <submit [at] flexiwebhost.com>
>>> wrote:
>>>
>>>>> It returns null, which brings up a blank image.
>>>> then you can simply do something such as:-
>>>>
>>>> <?PHP
>>>> $image = getRandomImage('LL/');
>>>> if (is_null($image))
>>>> {
>>>> $image = '';// Set to the image you wish
>>>> }
>>>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>>>> ?>
>>>>
>>>> in the if statement place the path and name of the image you want to use as
>>>> the image that will be displayed if nothing is returned from the function.
>>>>
>>> When I use this:
>>>
>>> <?php
>>> $image = getRandomImage('LL/');
>>> if (is_null($image))
>>> {
>>> $image = 'none.jpg';// Set to the image you wish
>>> }
>>> echo "<img src='$image' height=90 width=120 alt='LL'>";
>>> ?>
>>>
>>> and pull up the Web page I look at the source and I see this:
>>> <img src='' height=90 width=120 alt='LL'>
>>>
>>> As you can see the 'none.jpg' default file is not coded into
>>> the resulting HTML.
>>>
>>> Any idea why?
>>>
>>> Regards,
>>>
>>>
>>>
>>> Fred
>>>
>> Because it's returning an empty string - which is NOT the same as null.
>
> As you can see, I am defining the string as none.jpg. I can't
> imagine why it still thinks it is null.
>
>
>
>
> Fred
>

Read what I said again.

And no, you're not. You're checking:

if (is_null($image))

And the test is false because it's not null. So you're not setting it
to none.jpg.

It never was null, and PHP doesn't think it's null.

NULL IS NOT THE SAME AS AN EMPTY STRING!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Fr, 31 August 2007 03:49 ] [ ID #1809830 ]

Re: PHP Image by Default

> As you can see, I am defining the string as none.jpg. I can't
> imagine why it still thinks it is null.

As Jerry has pointed out. NULL and an empty string are 2 complete different
things. If the code I supplied is not working then the function is not
returning NULL it is returning an empty string.

That being the case change the is_null function to the empty function

<?PHP
$image = getRandomImage('LL/');
if (empty($image))
{
$image = '';// Set to the image you wish
}
echo "<img src='$image' height=90 width=120 alt='LL'>";
?>
Peter [ So, 02 September 2007 17:52 ] [ ID #1810751 ]

Re: PHP Image by Default

On Sun, 2 Sep 2007 16:52:26 +0100, "peter" <submit [at] flexiwebhost.com>
wrote:

>
>> As you can see, I am defining the string as none.jpg. I can't
>> imagine why it still thinks it is null.
>
>As Jerry has pointed out. NULL and an empty string are 2 complete different
>things. If the code I supplied is not working then the function is not
>returning NULL it is returning an empty string.
>
>That being the case change the is_null function to the empty function
>
><?PHP
>$image = getRandomImage('LL/');
>if (empty($image))
>{
> $image = '';// Set to the image you wish
>}
>echo "<img src='$image' height=90 width=120 alt='LL'>";
>?>
>

Gentlemen:

I thank you.

Your revision above didn't quite fit my application due to a
quirk in the program being called up (that I didn't show you). But
after I revised it a slight little bit, it did the job just perfectly.
Thank you both for your help. I got it working just fine.

My best regards, :-)



Fred Atkinson
Fred Atkinson [ Mo, 03 September 2007 03:15 ] [ ID #1811322 ]
PHP » alt.php » PHP Image by Default

Vorheriges Thema: PHP Mail gets blocked by spam filters
Nächstes Thema: php audio editing