Presentation is loading. Please wait.

Presentation is loading. Please wait.

V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 1.

Similar presentations


Presentation on theme: "V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 1."— Presentation transcript:

1 V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 1

2 V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 2

3 V 1.0 Directory Functions getcwd(), chdir() opendir(), readdir(), closedir(), rewinddir() scandir(), glob() realpath() 3 OE NIK 2013

4 V 1.0 GD Functions image*, http://php.net/manual/en/book.image.php $im=imagecreatefromjpeg($path) //png, gif, wbmp imagesy($im), imagesx($im) $index=imagecolorat($im, X, Y); $rgb=imagecolorsforindex($im, $index); $index=imagecolorallocate($im, R, G, B); imagesetpixel($im, X, Y, $index); 4 OE NIK 2013

5 V 1.0 GD Example – pagetitle.php 5 OE NIK 2013

6 V 1.0 GD Example – getChannel.php 6 OE NIK 2013

7 V 1.0 Upload file An HTML form should be used to upload files (files are sent after the request, just like the POST) MAX_FILE_SIZE, upload_max_filesize, max_file_uploads, post_max_size, LimitRequestBody 7 OE NIK 2013

8 V 1.0 Upload Example – Uploader.php $file="myfile"; $DIR_destination="images/" IF (valid upload file){ $name=create local name move uploaded file to location IF (jpeg) create thumbnail } Redirect user back to index.php 8 OE NIK 2013

9 V 1.0 Valid file? 9 OE NIK 2013

10 V 1.0 Create local name 10 OE NIK 2013

11 V 1.0 Move file? move_uploaded_file($old_name, $new_name); move_uploaded_file($_FILES[$file]["tmp_name"], $DIR_destination.$name); 11 OE NIK 2013

12 V 1.0 Create Thumbnail? 12 OE NIK 2013

13 V 1.0 EXERCISES (OPTIONAL) Create an upload form with a checkbox and four textboxes. If the checkbox is checked, then you should draw a rectangle to the thumbnail – the rectangle's coordinates are specified in the four textboxes Write a dynamically sized copyright note to the bottom- right corner of every uploaded image (imagettfbbox?) Draw 20 random lines to the image 13 OE NIK 2013

14 V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 14

15 V 1.0 Be sure to check for all possible errors/conditions in all the scripts (no input, bad input)! Direct access for HTML files is not allowed: the PHP files have to read and display the HTML files if there is no user input, and the proper output should be displayed if there is a user input. You can use xxxx.php?action=SOMETHING if you want, in this case: every PHP file will require two actions: one to display the HTML form, and another to display the output. The HTML form should POST all data to the second action. 15 OE NIK 2013

16 V 1.0 You should create a script to list the Fibonacci sequence. –Create a file 1_fibo.html that has a form inside: the form should have a text input, and a submit button. The form should submit all data via POST to 1_fibo.php. –Create a file 1_fibo.php that should list all elements of the Fibonacci sequence until the given number, and the script should decide if the last number is a perfect number or not. –[The first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two (0, 1, 1, 2, 3, 5, 8). A perfect number is a number that is half the sum of all of its positive divisors (including itself: (1 + 2 + 3 + 6 ) / 2 = 6) ] 16 OE NIK 2013

17 V 1.0 Improve the calculation of the Fibonacci sequence. –Create a file 2_fibo.html that can submit a number to 2_fibo.php via POST. In addition, there should be a select input where the user can choose to use the Fibonacci file or not. –If the user doesn’t want to use the Fibonacci file, then 2_fibo.php should simply calculate all Fibonacci numbers just like in exercise 1. –If the user wants to use the file, then 2_fibo.php should use a file to store the Fibonacci sequence (2_fibo.txt: in the beginning, the file is non-existent. Later, this file will grow!) Let’s say we have N Fibonacci numbers in the file, and the user wants M Fibonacci numbers. If M<=N, then read M Fibonacci numbers from the file, and write it out for the user. If M>N, then read all Fibonacci numbers from the file, write it out to the user. Then, calculate all remaining numbers, write it out to the user, and write it into the file as well. 17 OE NIK 2013

18 V 1.0 Visualize the calculation of the Fibonacci sequence. –Create a file 3_fibo.html that can submit a number to 3_fibo.php via POST. In addition, there should be a radiobutton input where the user can choose to receive a JPEG or a PNG file. –In 3_fibo.php, you should create a 1000x1000 image, and on that image you should write all Fibonacci numbers as a text (up to N, where N is the number the user entered. Every Fibonacci number should be in random colour and in random position! Use imagettftext / imagestring!) –Produce a blank red image without text if there are any errors. 18 OE NIK 2013

19 V 1.0 Recipe book Create an application to manage a recipe book The script should have actions to manage the ingredients.txt file: the file contains one ingredient per line; create actions to list them or add a new ingredient The script should have actions to manage the recipes.txt file: the file should have the entries in the format of: RECIPE_NAME|ingredient1,ingredient2,ingredient3 There should be an action to list all recipes (and the ingredients of the recipes) in a nice-looking table There should be an action to add a new recipe: first ask the recipe name and the number of ingredients; then input the ingredients (using selects), then save into the file OE NIK 2013 19

20 V 1.0 OE NIK 2013 20

21 21 OE NIK 2013


Download ppt "V 1.0 OE NIK 2013 PHP+SQL 7. Directory Management GD File Uploads Exercises 1."

Similar presentations


Ads by Google