6 Pages

Lecture 14 - Uploading files and PHP graphics

Course: INFO 2300, Spring 2008
School: Cornell
Rating:
 
 
 
 
 

Word Count: 1226

Document Preview

3, Reminder Project part I due tonight at midnight Uploading files and PHP graphics INFO/COM S 230: Intermediate Web Design and Programming Midterm info Time: 7:30-9PM, Tuesday 3/11 Place: Olin 155 Format: On paper Closed book, closed notes However, you can bring a 4"x6" index card of notes you made yourself (front and back). Coverage: Up to (and including) Monday's lecture on logins Review...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> Cornell >> INFO 2300

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
3, Reminder Project part I due tonight at midnight Uploading files and PHP graphics INFO/COM S 230: Intermediate Web Design and Programming Midterm info Time: 7:30-9PM, Tuesday 3/11 Place: Olin 155 Format: On paper Closed book, closed notes However, you can bring a 4"x6" index card of notes you made yourself (front and back). Coverage: Up to (and including) Monday's lecture on logins Review session Sunday, March 9 4-6PM Room: TBA Note: This is optional. Section Will distribute Lecture evaluation form Form to help us put together final project groups Group sizes 3-4 You can request to be in a group with someone else (from same section time), and we'll respect it if the choice is mutual Uploading files 1 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now. How to upload a file As you might suspect, file uploading is another HTML form. <form action="photoadmin.php" method="post" enctype="multipart/form-data"> <input type="file" name="newphoto" /> <input type="submit" name="Upload photo" /> </form> But what is on other side? Accessing the file Unlike other form data, information from file uploading shows up in $_FILES (rather than $_POST or $_GET). $_FILES[`newphoto'][`name'] original name of file $_FILES[`newphoto'][`tmp_name'] name of file in temporary storage $_FILES[`newphoto'][`size'] size in bytes of file $_FILES[`newphoto'][`type'] type of file (e.g. "image/jpeg" or "application/pdf") $_FILES[`newphoto'][`error'] error code (0 if no error) Moving the file move_uploaded_file(source, destination) Moves uploaded file out of temporary storage to wherever you want to keep it E.g. move_uploaded_file($_FILES[`newphoto'][`tmp_name'], "images/".$_FILES[`newphoto'][`name']); photoadmin.php Another useful function getimagesize(filename) Returns an array with various information about an image file. E.g. $array = getimagesize("myphoto.jpg"); $array[0]=image width $array[1]=image height $array[2]=code for image type $array[3]=`height="ht" width="wt" ` <?php if (isset($_FILES['newphoto'])) { if ($_FILES['newphoto']['error'] == 0) { move_uploaded_file($_FILES['newphoto']['tmp_name'], "./".$_FILES['newphoto']['name']); $_SESSION['photos'][ ] = $_FILES['newphoto']['name']; print("The file ".$_FILES['newphoto']['name']." was uploaded successfully.\n"); } else { print("The file ".$_FILES['newphoto']['name']." was not uploaded.\n"); } } ?> <form action="photoadmin.php" method="post" enctype="multipart/form-data"> Photo: <input type="file" name="newphoto" /><br /> <input type="submit" value="Upload photo" /> </form> 2 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now. photo.php <?php foreach ($_SESSION['photos'] as $photo) { $imagesize = getimagesize($photo); print("<img src=\"$photo\" $imagesize[3] /><br />\n"); } ?> PHP Graphics Graphics It is possible to create images "on the fly" with PHP via a graphics package gd2. GD2 is not enabled by default with PHP. However, it is on the 230 server, and it is not too hard to enable on Windows installations (see PHP forum). Credits There's tons to cover on PHP graphics; we're only scratching the surface. To learn more, see the following nice introduction about PHP graphics: http://www.nyphp.org/content/presentatio ns/GDintro/ Including a PHP-generated image No different than including any other image. <img src="myimage.php" height="200" width="200" alt="A random image" /> The general form 1. Create an image of specified size in memory. 2. Put content in the image (shapes, text, etc.) 3. Output a header (so your browser knows it is an image, and not HTML) 4. Output the image 5. Free the memory used to create the image. 3 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now. Most of the steps imageCreate(width, height) imageCreateTrueColor(width, height) Returns an image resource of width pixels by height pixels. header(`image/png') header(`image/jpeg') Outputs headers for PNG or JPEG type images respectively. Most of the steps imagePNG(image) imageJPEG(image) Given an image resource, outputs a PNG or JPEG image respectively. imageDestroy(image) an Given image resource, frees the memory associated with the image. Example <?php $im = imageCreate(200, 200); // Do the interesting stuff here header(`image/PNG'); imagePNG($im); imageDestroy($im); ?> The interesting stuff We can specify the colors we will use in RGB format. imageColorAllocate(image, red, green, blue) Returns a color resource E.g. $white = imageColorAllocate($im, 0xFF, 0xFF, 0xFF); $black = imageColorAllocate($im, 0, 0, 0); Lines imageLine(image, x1, y1, x2, y2, color) Draws a line on image of color color from (x1,y1) to (x2,y2) (0,0) (width, 0) Rectangles imageRectangle(image, x1, y1, x2, y2, color) Draws a rectangle in image of color color with opposite corners at (x1,y1) and (x2, y2) imageFilledRectangle(image, x1, y1, x2, y2, color) Same as above, but rectangle is filled in. (0,height) 4 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now. <?php Ellipses imageEllipse(image, x, y, w, h, color) Draws an ellipse of color color centered at (x,y) of width w and height h imageFilledEllipse(image, x, y, w, h, color) Same as above, but ellipse is filled in ?> $im = imageCreate(500, 500); $black = imageColorAllocate($im, 0, 0, 0); $blue = imageColorAllocate($im, 0, 0, 0x80); $red = imageColorAllocate($im, 0x80, 0, 0); imageLine($im, 20, 20, 300, 400, $black); imageRectangle($im, 200, 10, 100, 100, $red); imageFilledRectangle($im, 200, 490, 100, 400, $blue); imageEllipse($im, 150, 250, 100, 200, $blue); imageFilledEllipse($im, 150, 100, 75, 75, $red); header('Content-type: image/png'); imagePNG($im); imageDestroy($im); Why...? For fixed images, probably would rather use a drawing program. But helpful for drawing images based on user input, database information, etc. A clock $im = imageCreate(500, 500); $white = imageColorAllocate($im, 0xFF, 0xFF, 0xFF); $black = imageColorAllocate($im, 0, 0, 0); $blue = imageColorAllocate($im, 0, 0, 0x80); imageFilledEllipse($im, 250, 250, 450, 450, $black); imageFilledEllipse($im, 250, 250, 430, 430, $blue); imageFilledEllipse($im, 250, 250, 410, 410, $white); imageSetThickness($im, 10); $array = getMinuteHand(250, 250, 180); \\ use date function to get minute imageLine($im, $array[0], $array[1], $array[2], $array[3], $black); imageSetThickness($im, 20); $array = getHourHand(250, 250, 140); \\ use date function to get hour imageLine($im, $array[0],$array[1], $array[2], $array[3], $black); header('Content-type: image/png'); imagePNG($im); imageDestroy($im); Drawing on existing images imageCreateFromPNG(filename) imageCreateFromGIF(filename) imageCreateFromJPEG(filename) Use as a starting image the given PNG/GIF/JPEG. $im = imageCreateFromGIF("tower.gif"); $white = imageColorAllocate($im, 0xFF, 0xFF, 0xFF); $black = imageColorAllocate($im, 0, 0, 0); imageSetThickness($im, 3); $array = getMinuteHand(48, 276, 30); imageLine($im, $array[0], $array[1], $array[2], $array[3], $black); imageSetThickness($im, 4); $array = getHourHand(48, 276, 20); imageLine($im, $array[0],$array[1], $array[2], $array[3], $black); header('Content-type: image/png'); imagePNG($im); imageDestroy($im); 5 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now. Using PHP Graphics to make thumbnails Instead, we can use PHP graphics to save a smaller, resized version of our photo (a "thumbnail"), which we can show instead. $img = imagecreatefromjpeg("./".$_FILES['newphoto']['name']); $width = imagesx($img); $height = imagesy($img); $thumb_width = 200; $new_width = $thumb_width; $new_height = floor($height * ($thumb_width/$width)); $new_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($new_img, "./thumbs/".$_FILES['newphoto']['name']); imageDestroy($img); imageDestroy($new_img); imagesx(image), imagesy(image) Gives width, height of image. imageCopyResized(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_width, dst_height, src_width,src_height) (also imageCopyResampled) Copy a rectangle from src_img to dst_img with resizing (Resampled also tries to interpolate colors to keep image clarity). imageJPEG(image, filename) Saves image in JPG file filename. Review Upload files via input type="file"; use results on PHP side via $_FILES. Can draw images using data from user input, databases, other sources with PHP graphics. Project 3 6 Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now.
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Cornell - ILROB - 4710
GROUND RULES FOR COLLABORATIVE LAW PROCESS 1. 2. 3. 4. Attack the problems and concerns at hand, not each other. Avoid positions; rather, express yourself in terms of needs and interests and the outcomes you would like to achieve. Work for what you b
Cornell - ILROB - 4710
COLLABORATIVE LAW PARTICIPATION AGREEMENTI. PURPOSE_ and his/her attorney, _, and_ and his/her attorney, _, have chosen to use the principles of Collaborative Law to settle the issues arising from the dissolution of their marriage or domestic part
Cornell - ILROB - 4710
Cornell - ILROB - 4710
Warning Concerning Copyright Restrictions The copyright law of the United States (Title 17, United States Code) governs the making of photocopies or other reproductions of copyrighted material. Under certain conditions specified in the law, libraries
Cornell - ILROB - 4710
Cornell - ILROB - 4710
Warning Concerning Copyright Restrictions The copyright law of the United States (Title 17, United States Code) governs the making of photocopies or other reproductions of copyrighted material. Under certain conditions specified in the law, libraries
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor Michele WilliamsAgenda Turn in Post-Negotiation Paper (upload a copy onto Blackboard!) In the News Integrative Bargaining (reviewed) Exercise Video Case and Debrief Wrap-up 2008 Michele Willi
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor Michele WilliamsAgenda Getting to Yes Conflict Exercise El-Tek Discussion and Wrap-up 2007 Michele Williams. All Rights Reserved.Pilots Thwart Merger Plans 2007 Michele Williams. All Right
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor Michele WilliamsAgenda Emotion, Power and Negotiation Style (The Coleman account ) Reflective Paper Assignment Amanda Dispute Discussion and Wrap-up Gender (next week) 2007 Michele Williams.
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor WilliamsAgenda Distributive Tactics Negotiation Exercise (Used Car) Fishbowl Negotiation Break Auction Netscape Case Discussion Wrap-upFocusStrategy Distributive (fixed-pie) Integrative (
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor Michele WilliamsAnnouncement: Sign out an IClickerAgenda In the News Negotiation Paradigms Psychological Biases Personal Experience Coffee Contract Double Negotiation Discussion Video and W
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor WilliamsAgenda Ethics In the News Negotiation Preparation Break Negotiation Discussion and Wrap-up Post Negotiation Analytic PaperA Question of Ethics You see a sign on a vacation home,
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor WilliamsProfessor Michele WilliamsTeaching Assistant:Chia-Ming Chan, cc489@cornell.eduAgenda Introduction and Overview Syllabus Break Negotiation Exercise Discussion Wrap-upWe negotiate
Cornell - ILROB - 4710
ILROB 471 Organizations and NegotiationProfessor Michele Williams 2008 Michele Williams. All Rights Reserved.Agenda Gender Dispute Resolution Frameworks Emotion Management Tool Kit Telepro Negotiation Discussion and Wrap-up Mediation in Ac
Cornell - ILROB - 4710
Berkeley - MATH - 16A
016A S2 Homework 1 SolutionJae-young Park September 2, 2007 0.1 *10 Use intervals to describe the real numbers satisfying the inequality x -1 and x &lt; 8. Solution You may change the expression little bit: -1 x &lt; 8, which is equivalent. Using inte
E. Michigan - PHYS - 221
E. Michigan - CHEM - 371
CHEM 371 Fall 2007 Professor Wilmes Exam 4 50 minutesName_ EMU ID#_ By signing below, I state that I agree to and will follow all aspects of the Student Conduct Code with regard to academic honesty: Signature__Instructions: This is a closed book
E. Michigan - CHEM - 372
E. Michigan - CHEM - 372
E. Michigan - CHEM - 372
E. Michigan - CHEM - 372
Penn State - ENGL - 015
LJ Palombo 10/15/07 Ms. Spanier To Party or Not to Party To live a healthy life, you must find a balance your free time. You should use some of your time for work and some for play. My preferred form of play would be to party. By party, I mean to go
Penn State - KINES - 061
LJ Palombo Target Heart Rate Training Zone : 121 181 bpmWorkout 1 20 minutes of cardio work (aerobics) Lower Body: (1 set, 10-12 reps) Leg Press - machine Leg Extension - machine Leg Curl - machine Lunge - dumbbell Upper Body: (1 sets, 8-10 reps)
Michigan - ENG - 125
Curtice 1 (I am sorry that I sent you the incorrect version, I saved these paper versions as Escuerdo4 and Escudero4 on my laptop and I think that this was an accident.) Mark Curtice English 125 section 56 Instructor Escudero This is a much better pa
E. Michigan - PHY - 221
Penn State - COMM - 150
1 Comm. 150 SoundIn this scholarly article I will be analyzing the use of sound in Superbad. I this film I chose one scene in particular and it's the one where the two cops pick up McLovin and take him to an abandoned parking lot. When the three ar
Penn State - HIST - 011
1 As a young adult Adolf Hitler was failing high school and wanted to pursue a career in art, but was not accepted into the art schools. Spending most of his adolescent years poor and jobless, he would beg for money and food. Later he volunteered to
Penn State - COMM - 150
1Comm. 150 CinematographyThe film images create a depth of field, which is the distance before and behind the main focus. In the film Billy Madison, you can clearly see the attribute of depth of field when Billy goes back to school and is sitting
Penn State - HIST - 011
Chp 24: The New Imperialism, 1869-1914 The New Imperialism: Motives and Methods -Explosion of territorial conquests in 16th century -10 million sq. miles and 150 million people were ruled by Europe and the United States during this time Political Mot
Penn State - COMM - 150
1Comm. 150 EditingEditing is the only form which is unique to cinema. In the film Longest Yard, the newer version with Adam Sandler is what I saw as a good film to analyze for its editing techniques. I realized that there are no limits in editing
Michigan - ANTHRO - 101
ANTHRO Lecture 9-18-07 Culture &quot;Codebook&quot; of reality; transforms physical reality Into experienced reality Systems of proof vary in different cultures Reality is subjective Picasso what criticized for distorting human features We learn what standard
Michigan - ANTHRO - 101
Lecture 9-20 Holism: define (look in textbook) Earth is 15 billion years old Carl sagan: &quot;Cosmic Calendar&quot; Every billion years = 24 days Every 475 = 1 second Jan 1: origin of the universe May 1: origin of the milky way humans: have only been here for
Michigan - ANTHRO - 101
October 9, 2007 Lecture Tectonic and Landforms Below, crust, Below lithosphere, is the liquid asthenosphere Earth works much like a convection over, the core is hot enough for convection through the mantel Patterns of landscape on earth are a result
Michigan - ANTHRO - 101
Fluvial systems: where do rivers come from? Hydrologic cycle Evapotranspiration Precipitation Infiltration Runoff Ground water: water table rises after rain, lowers during drought Carbonic acid action dissolves limestone, producing caverns Cavern col
Michigan - GEOSCI - 201
Nate Strick GEOSCI 201 Lab: due September 19, 2007Question 1) The earth's atmosphere is thickening, which will have dramatic and rapid effects of the Earth's climate. Carbon Dioxide levels in the atmosphere have gone up since Roger Kevelle first st
Michigan - SAC - 236
John Sharp SAC 236 Section 006Hustle &amp; FlowChris Brewer, independent film director and writer of Hustle &amp; Flow, along with lead actor Terrence Howard's truly riveting performance transformed the genre and made it present. Hustle &amp; Flow picked up w
Michigan - SAC - 236
John J Sharp October 9, 2007 SAC 236 / RC 236Alfred Hitchcock's NotoriousThe shot I chose for part A of the exercise starts at 3:26 after the camera pans right across Cary Grant's back and comes to rest behind his right shoulder. The camera is pl
Michigan - SAC - 236
John Sharp SAC 236 Section 006Alfred Hitchcock's North by NorthwestThe scene I chose for part A of the exercise begins at 00:08:38 of part one and ends at 00:03:45 of part two after Cary Grant is taken to Lester Townsend's house. This scene begins
Michigan - SAC - 236
John Sharp October 18, 2007 SAC 236 Section 006Alfred Hitchcock's Rear WindowThe shot I chose for part A of the exercise starts at 00:39:32 as the subjective camera tilts down facing out of James Stewart's apartment rear window. The window and sil
Michigan - SAC - 236
The sound I chose for part A of the exercise starts at 00:32:30 as James Stewart, Doris Day, and Bernard Miles enter the Marakesh Police Station. This scene takes place immediately following the murder of Louis Bernard at the Marakesh Police Station
E. Michigan - MATH - 107
Michigan - ENG - 125
Mark Curtice Instructor Escuerdo English 125 section 56 Cum Hoc Fallacy The Cum Hoc Ergo Propter Hoc is an Informal fallacy of the sub family of the Non Causa Pro Causa (Curtis). The fallacy type involves a premise that does not carry the burden of p
UGA - RELI - 1001
RELI 1001 Rothacker MWF Judaism Unit Review Religion-is seeking and responding to that which humans experience as ultimate or holy (Dr. Roger Schmidt) o Ultimate-most important; defines one's existence o Holy-sacred; set apart o Religion comes from r
Michigan - ENG - 125
Mark Curtice Instructor Escudero English 125 section 56 March 11, 2008 Common Place Book and Writing Journal 3 Common Place Book1 A &quot;Imagine waking up in the morning, looking out your window and seeing this view. Breathtaking,isn't it? What would
Michigan - ENG - 125
Mark Curtice English 125 sec. 026 Professor Escuerdo January 16, 2008 Essay- How does the style match the purpose? The style of &quot;Acquiring a Japanese Family&quot;, &quot;Palestinian Like Me&quot;, and &quot;37 Just Walk By: Black Men and Public Space&quot; matches the author
E. Michigan - MATH - 107
E. Michigan - MATH - 107
Michigan - ENG - 125
Mark Curtice English 125 section 56 Instructor Escuerdo Common Place book and writing journal I. 1. Expect money market mutual fund yields to fall three-quarters of a percentage point, to about 3.25%, within the next 30 days, says Peter Crane, presid
UGA - RELI - 1001
RELI 1001 ROTHACKER MWF CHRISTIANITY MAIN POINTS Christianity-trinitarian monotheism Jesus of Nazareth 4 bce- 30 ce o Didn't call him Jesus he was called Yesuwah, relating to Joshua Christ of Faith = central doctrine o Devotional approach; church/Sun
E. Michigan - ACC - 241
Johana Castillo E00035787 ACC 241 Computer Project One TR 1:00pm-2:15pm Prepared for Dr. Okopny Double Diamond Skis Shaping and Milling Department Production Report (Weighted Average Method) Quantity Schedule and Equivalent UnitsQuantity Schedule U
E. Michigan - ACC - 241
Johana Castillo E00035787 ACC 241 Computer Project Three TR 1:00pm -2:15pm Prepared for Dr. Okopny Down Under Products, Ltd. Second Quarter Production Budget Total for Quarter 195,000 27,540 222,540 16,050 206,490Budgeted sales Add desired ending i
E. Michigan - ACC - 241
Johana Castillo E00035787 ACC 241 Computer Project Two TR 1:00pm - 2:15pm Prepared for Dr. OkopnyACOUSTIC CONCEPTS, INC. Contribution Income Statement For the Month of JuneSales Less: Variable expenses Contribution margin Less: Fixed expenses Net
Michigan - ENG - 125
Mark Curtice English 125 section 56 Instructor EscuerdoResubmissionCommon Place book and writing journal I. 1. Expect money market mutual fund yields to fall three-quarters of a percentage point, to about 3.25%, within the next 30 days, says Peter
UGA - GEOL - 1121
Chapter 1 History of Universe: Earth-only planet w/ liquid water on surface Started w/ Big Bang 15 billion yrs ago Composition today: 75% H, 23% He, 2% other Expansion: galaxies are separating Matter distributed in clouds &amp; within smaller clouds
N.C. State - BIO - 181/183
Karmen Best BIO 181L sec 240 11/26/07Protein Isolation by Means of ElectrophoresisIntroduction The purpose of the protein isolation lab is to gain more knowledge about molecules and how they are isolated and separated by electrophoresis. Understa
N.C. State - BIO - 181/183
N.C. State - CH - 201
Explicit values for -version -version is directly analogous. Problem I. See WA Q01, #s 2, 5, 7, 8. Exp. 1.6 of text. Mass percent oxygen:CH201 Examination I solutions and references72.1 mgO 100 20.6% (19.4% on -version) 350 mg TotEmpirical fo
N.C. State - PY - 211
Uniform Circular MotionKarmen Best, kdbest@ncsu.edu Al Ryan, Lab Partner PY211L Section 208 Leslie Watkins, TA Lab Performed: 03/11/08 Lab Turned In: 03/18/08Introduction The objective of this weeks lab was to explore uniform circular motion as i