tailieunhanh - Giải pháp thiết kế web động với PHP - p 25

GENERATING THUMBNAIL IMAGES It doesn t matter which order your methods appear inside the class definition, but it s common practice to keep all public methods together after the constructor and to put protected methods at the bottom of the file. This makes the code easier to maintain. Insert the following definition between the constructor and the checkType() definition: public function test() { echo 'File: ' . $this-_original . ''; echo 'Original width: ' . $this-_originalwidth . ''; echo 'Original height: ' . $this-_originalheight . ''; echo 'Image type: ' . $this-_imageType . ''; if ($this-_messages) { print_r($this-_messages); } } This. | GENERATING THUMBNAIL IMAGES It doesn t matter which order your methods appear inside the class definition but it s common practice to keep all public methods together after the constructor and to put protected methods at the bottom of the file. This makes the code easier to maintain. Insert the following definition between the constructor and the checkType definition public function test echo File . this- _original . br echo Original width . this- _originalwidth . br echo Original height . this- _originalheight . br echo Image type . this- _imageType . br if this- _messages print_r this- _messages This uses echo and print_r to display the value of the properties. 6. To test the class definition so far save and add the following code block above the DOCTYPE declaration in the code is in and in the ch08 folder php if isset _POST create require_once . classes Ps2 try thumb new Ps2_Thumbnail _POST pix thumb- test catch Exception e echo e- getMessage The name of the submit button in is create so this code runs only when the form has been submitted. It includes the Ps2_Thumbnail class definition creates an instance of the class passing the selected value from the form as an argument and calls the test method. 7. Save and load it into a browser. Select an image and click Create Thumbnail. This produces output similar to Figure 8-1. 221 CHAPTER 8 Download from Wow eBook Figure 8-1. Displaying the details of the selected image confirms the code is working. If necessary check your code against Thumbnail_01. php in the ch08 folder. Although some properties have default values you need to provide the option to change them by creating public methods to set the maximum size of the thumbnail image and the suffix applied to the base of the filename. You also need to tell the class where to create the thumbnail. The formal term for this type

TỪ KHÓA LIÊN QUAN