problem with POST and if statements – PHP

  php

Q(Question):

I have an image viewing page which resizes an image to a sensible sizebefore
displaying. The user should then be able to choose "25% larger" or smaller
and the resized image display. The problem I am getting with the code below
is that whatever the POST variable value (and I have tested the value
changes correctly), the line marked with *** executes, ie the image gets
smaller. Am I missing some obvious subtlety with IF statements?

Also, when the page reloads, it still displays the previous (ie non-resized)
image, despite the fact that I have confirmed that the actual image in the
directory has changed size. Is it the case that the image has been cached by
the browser? If so, how do I force a reload?

TIA Gaz

if(isset($_POST[‘submitScale’])) {
if ($_POST[‘scale’] = "25% smaller") {
resizeImageByPercent($thumbLocation, "resized", 75);
}
else if ($_POST[‘scale’] = "25% larger") {
resizeImageByPercent($thumbLocation, "resized", 125);
}
else if ($_POST[‘scale’] = "full size") {
resizeImageByPercent($originalLocation, "resized", 100);
}
}

…..blah blah blah some code

<form action="imageview.php3?image_id=<?echo $row["image_id"]?>"
method="POST">
Make this image&nbsp;<select name="scale">
<option>25% smaller
<option>25% larger
<option>full size
</select>
<input type="submit" name="submitScale" value="Go!">
</form>

A(Answer):

"GazK" <to*****@blueyonder.co.uk> wrote in message
news:mk****************@news-binary.blueyonder.co.uk…

I have an image viewing page which resizes an image to a sensible
sizebefore displaying. The user should then be able to choose "25% larger" or smaller
and the resized image display. The problem I am getting with the code
below is that whatever the POST variable value (and I have tested the value
changes correctly), the line marked with *** executes, ie the image gets
smaller. Am I missing some obvious subtlety with IF statements?

Also, when the page reloads, it still displays the previous (ie
non-resized) image, despite the fact that I have confirmed that the actual image in the
directory has changed size. Is it the case that the image has been cached
by the browser? If so, how do I force a reload?

This is how I tell the browser not to cache something:

header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’);
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’).’ GMT’);
header(‘Cache-Control: no-cache, must-revalidate’);
header(‘Pragma: no-cache’);

I think I got this out of the PHP manual when looking up how to use the
header() function. Oh, if you’re serving images off of the file system (and
not through a database or other dynamic means), I’ve found it works to read
the file in using fread() and send it to the client with the appropriate
"Content-Type" header. I created a bandwidth meter in PHP that used an
image file to test the transfer rate between a client and my server. It
seemed that the easiest way to make sure the image was never cached by the
browser was to use PHP (and the non-caching headers) to send the file
manually. (I’m sure there’s an Apache work-around, though.)

By the way, are you changing the "width" and "height" attributes of your
image tag on the front end?

HTH,
Zac

A(Answer):

> I have an image viewing page which resizes an image to a sensible
sizebefore

displaying. The user should then be able to choose "25% larger" or smaller
and the resized image display. The problem I am getting with the code
below is that whatever the POST variable value (and I have tested the value
changes correctly), the line marked with *** executes, ie the image gets
smaller. Am I missing some obvious subtlety with IF statements?

Also, when the page reloads, it still displays the previous (ie
non-resized) image, despite the fact that I have confirmed that the actual image in the
directory has changed size. Is it the case that the image has been cached
by the browser? If so, how do I force a reload?

TIA Gaz

if(isset($_POST[‘submitScale’])) {
if ($_POST[‘scale’] = "25% smaller") {
resizeImageByPercent($thumbLocation, "resized", 75);***
}
else if ($_POST[‘scale’] = "25% larger") {
resizeImageByPercent($thumbLocation, "resized", 125);
}
else if ($_POST[‘scale’] = "full size") {
resizeImageByPercent($originalLocation, "resized", 100);
}
}

….blah blah blah some code

<form action="imageview.php3?image_id=<?echo $row["image_id"]?>"
method="POST">
Make this image&nbsp;<select name="scale">
<option>25% smaller
<option>25% larger
<option>full size
</select>
<input type="submit" name="submitScale" value="Go!">
</form>

A(Answer):

"GazK" <to*****@blueyonder.co.uk> wrote in message
news:nG*****************@news-binary.blueyonder.co.uk…

I have an image viewing page which resizes an image to a sensible sizebefore

displaying. The user should then be able to choose "25% larger" or
smaller and the resized image display. The problem I am getting with the code

below

is that whatever the POST variable value (and I have tested the value
changes correctly), the line marked with *** executes, ie the image gets
smaller. Am I missing some obvious subtlety with IF statements?

Also, when the page reloads, it still displays the previous (ie

non-resized)

image, despite the fact that I have confirmed that the actual image in
the directory has changed size. Is it the case that the image has been

cached by

the browser? If so, how do I force a reload?

TIA Gaz

if(isset($_POST[‘submitScale’])) {
if ($_POST[‘scale’] = "25% smaller") {
resizeImageByPercent($thumbLocation, "resized", 75);***
}
else if ($_POST[‘scale’] = "25% larger") {
resizeImageByPercent($thumbLocation, "resized", 125);
}
else if ($_POST[‘scale’] = "full size") {
resizeImageByPercent($originalLocation, "resized", 100);
}
}

There’s your first problem. Use "==" for comparison, and "=" for
assignment. Assignment returns the value assigned.

-Zac

A(Answer):

"Martin Wickman" <wi*****@hotbrev.com> wrote in message
news:bf************@ID-156202.news.uni-berlin.de…

Other than that, try a force reload of your browser to make sure you
dont have any nasty cache problems.

Kinda offtopic, but I didn’t think POST requests were allowed to be cached
anyway.

A(Answer):

In article <bf************@ID-194542.news.uni-berlin.de>, Leslie Hoare wrote:

"Martin Wickman" <wi*****@hotbrev.com> wrote in message
news:bf************@ID-156202.news.uni-berlin.de…

Other than that, try a force reload of your browser to make sure you
dont have any nasty cache problems.

Kinda offtopic, but I didn’t think POST requests were allowed to be cached
anyway.

Well, try posting something and then reload. See, the browser keeps
the stuff cached. About ‘allowed’ or not. I dont know, but I would
guess that it’s up to each browser to decide whether it should cache
and not.

A(Answer):

doh! thanks, that fixed that part of the problem.

"Zac Hester" <ne**@planetzac.net> wrote in message
news:3f********@news.enetis.net…

"GazK" <to*****@blueyonder.co.uk> wrote in message
news:nG*****************@news-binary.blueyonder.co.uk…

I have an image viewing page which resizes an image to a sensible

sizebefore

displaying. The user should then be able to choose "25% larger" or smaller and the resized image display. The problem I am getting with the code

below

is that whatever the POST variable value (and I have tested the value
changes correctly), the line marked with *** executes, ie the image
gets smaller. Am I missing some obvious subtlety with IF statements?

Also, when the page reloads, it still displays the previous (ie

non-resized)

image, despite the fact that I have confirmed that the actual image in the directory has changed size. Is it the case that the image has been

cached

by

the browser? If so, how do I force a reload?

TIA Gaz

if(isset($_POST[‘submitScale’])) {
if ($_POST[‘scale’] = "25% smaller") {
resizeImageByPercent($thumbLocation, "resized", 75);***
}
else if ($_POST[‘scale’] = "25% larger") {
resizeImageByPercent($thumbLocation, "resized", 125);
}
else if ($_POST[‘scale’] = "full size") {
resizeImageByPercent($originalLocation, "resized", 100);
}
}

There’s your first problem. Use "==" for comparison, and "=" for
assignment. Assignment returns the value assigned.

-Zac

LEAVE A COMMENT