วันเสาร์ที่ 27 กรกฎาคม พ.ศ. 2556
test
Warning Watch your square brackets ([ ]) and parentheses carefully here; it’s really easy to get them
mixed up and cause a hard-to-find error.
But this code is a little longer, while the code without the if is just a little clearer.
Every bit of complexity you can save helps, so this is a nice trick to add to your
growing PHP toolkit.
You can actually check your code in action at this point. Visit create_user.html and
find an image file that’s bigger than 2 MB. Look for a photo in iPhoto or something
you’ve pulled straight off your camera. Select that image, and then try and submit
your form. You should get something like Figure 8-5 back.
Figure 8-5
Here’s one of those
beautiful situations where
a lot of hard work earlier
pays off later. Rather than
wading through your
code or even writing custom
PHP, you were able to
quickly hand off an error
to your handle_error
function and get a nice
response. Now multiply
that by the hundreds
(thousands?) of times
you’ll use handle_error,
and you’ll start to see the
value of having that utility
function written early
on in your PHP life.
Note You might have noticed that even though the image was rejected, your browser still uploads the
image—regardless of how big the image is, or what your maximum file size is. That’s because it’s only after
the image is uploaded that the size comparison is made. Sort of a bummer, but that’s a browser issue, and not
something you can fix with PHP.
This page is the result of your code finding an error code, and that error code being
matched up to an error in $php_errors—in this case, the image was larger than your
HTML allowed.
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น