PHP Image by Default
am 27.08.2007 03:36:58 von Fred Atkinson
Greetings,
I need some help on revising a simple PHP script. The script
I currently have is:
$image = getRandomImage(LL/');
echo "";
?>
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
Re: PHP Image by Default
am 27.08.2007 04:22:44 von Peter
> I need some help on revising a simple PHP script. The script
> I currently have is:
>
>
> $image = getRandomImage(LL/');
> echo "";
> ?>
>
> 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)
Re: PHP Image by Default
am 28.08.2007 05:21:43 von Fred Atkinson
On Mon, 27 Aug 2007 03:22:44 +0100, "peter"
wrote:
>
>> I need some help on revising a simple PHP script. The script
>> I currently have is:
>>
>>
>> $image = getRandomImage(LL/');
>> echo "";
>> ?>
>>
>> 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
Re: PHP Image by Default
am 28.08.2007 17:17:09 von Peter
> It returns null, which brings up a blank image.
then you can simply do something such as:-
$image = getRandomImage('LL/');
if (is_null($image))
{
$image = '';// Set to the image you wish
}
echo "";
?>
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.
Re: PHP Image by Default
am 30.08.2007 06:09:49 von Fred Atkinson
On Tue, 28 Aug 2007 16:17:09 +0100, "peter"
wrote:
>
>> It returns null, which brings up a blank image.
>
>then you can simply do something such as:-
>
>
>$image = getRandomImage('LL/');
>if (is_null($image))
>{
> $image = '';// Set to the image you wish
>}
>echo "";
>?>
>
>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:
$image = getRandomImage('LL/');
if (is_null($image))
{
$image = 'none.jpg';// Set to the image you wish
}
echo "";
?>
and pull up the Web page I look at the source and I see this:
As you can see the 'none.jpg' default file is not coded into
the resulting HTML.
Any idea why?
Regards,
Fred
Re: PHP Image by Default
am 30.08.2007 06:14:36 von Jerry Stuckle
Fred Atkinson wrote:
> On Tue, 28 Aug 2007 16:17:09 +0100, "peter"
> wrote:
>
>>> It returns null, which brings up a blank image.
>> then you can simply do something such as:-
>>
>>
>> $image = getRandomImage('LL/');
>> if (is_null($image))
>> {
>> $image = '';// Set to the image you wish
>> }
>> echo "";
>> ?>
>>
>> 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:
>
>
> $image = getRandomImage('LL/');
> if (is_null($image))
> {
> $image = 'none.jpg';// Set to the image you wish
> }
> echo "";
> ?>
>
> and pull up the Web page I look at the source and I see this:
>
>
> 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@attglobal.net
==================
Re: PHP Image by Default
am 31.08.2007 03:31:40 von Fred Atkinson
On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle
wrote:
>Fred Atkinson wrote:
>> On Tue, 28 Aug 2007 16:17:09 +0100, "peter"
>> wrote:
>>
>>>> It returns null, which brings up a blank image.
>>> then you can simply do something such as:-
>>>
>>>
>>> $image = getRandomImage('LL/');
>>> if (is_null($image))
>>> {
>>> $image = '';// Set to the image you wish
>>> }
>>> echo "";
>>> ?>
>>>
>>> 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:
>>
>>
>> $image = getRandomImage('LL/');
>> if (is_null($image))
>> {
>> $image = 'none.jpg';// Set to the image you wish
>> }
>> echo "";
>> ?>
>>
>> and pull up the Web page I look at the source and I see this:
>>
>>
>> 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
Re: PHP Image by Default
am 31.08.2007 03:49:52 von Jerry Stuckle
Fred Atkinson wrote:
> On Thu, 30 Aug 2007 00:14:36 -0400, Jerry Stuckle
> wrote:
>
>> Fred Atkinson wrote:
>>> On Tue, 28 Aug 2007 16:17:09 +0100, "peter"
>>> wrote:
>>>
>>>>> It returns null, which brings up a blank image.
>>>> then you can simply do something such as:-
>>>>
>>>>
>>>> $image = getRandomImage('LL/');
>>>> if (is_null($image))
>>>> {
>>>> $image = '';// Set to the image you wish
>>>> }
>>>> echo "";
>>>> ?>
>>>>
>>>> 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:
>>>
>>>
>>> $image = getRandomImage('LL/');
>>> if (is_null($image))
>>> {
>>> $image = 'none.jpg';// Set to the image you wish
>>> }
>>> echo "";
>>> ?>
>>>
>>> and pull up the Web page I look at the source and I see this:
>>>
>>>
>>> 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@attglobal.net
==================
Re: PHP Image by Default
am 02.09.2007 17:52:26 von Peter
> 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
$image = getRandomImage('LL/');
if (empty($image))
{
$image = '';// Set to the image you wish
}
echo "";
?>
Re: PHP Image by Default
am 03.09.2007 03:15:39 von Fred Atkinson
On Sun, 2 Sep 2007 16:52:26 +0100, "peter"
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
>
>
>$image = getRandomImage('LL/');
>if (empty($image))
>{
> $image = '';// Set to the image you wish
>}
>echo "";
>?>
>
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