Producing Participatory Media
Class 7 - July 22
Topics:
PHP 101
Basic HTML
<html> <!-- Required for all HTML pages --> <head> <title>The Top Bar Title</title> </head> <body> Some information <!-- A Comment Tag --> </body> </html> <!-- Closing tag, required -->Example 1
<html> <!-- Required for all HTML pages --> <head> <title>The Top Bar Title</title> </head> <body> Some information <br> <!-- A line break --> <!-- A Comment Tag --> <? // Denotes the start of PHP processing echo "The Date and Time is: "; // print a string, end with a semicolon $mydata = "July 29, 2004"; // Assign a variable echo $mydata; // print the string variable ?> </body> </html> <!-- Closing tag, required -->Example 2
<? function printDate() { echo "The Date and Time is: "; $mydata = "Feb. 27, 2007"; echo $mydata; } ?> <html> <head> <title>The Top Bar Title</title> </head> <body> <? printDate(); ?> </body> </html>Example 3
<? function printDate() { echo "The Date and Time is: "; $mydata = date("g:i:s A T D. M, j Y"); /* -- Multiline comment "date" is a built-in function that has some interesting formatting capabilities. */ echo $mydata; } ?> <html> <head> <title>The Top Bar Title</title> </head> <body> <? printDate(); ?> </body> </html>Example 4
<html> <head> <title>A Basic HTML Form</title> </head> <body> <form action="form_example.php" type="get"> First Name:<input type="text" name="first_name"><br> Last Name: <select name="last_name"> <option value="Smith">Smith</option> <option value="Doe">Doe</option> </select> <br> <input type="submit" value="Submit Me"> </form> </body> </html>HTML Form Example
<? /* Description: Helper function to get values from a form post (type="post" or query string (type="get") Returns: value of key or null on failure */ function getPOSTorGETValue($key) { if (isset($_POST[$key])) { $value = $_POST[$key]; } else if (isset($_GET[$key])) { $value = $_GET[$key]; } else { $value = null; } return $value; } ?> <html> <head> <title>The Form Output</title> </head> <body> <? $first_name = getPOSTorGETValue("first_name"); $last_name = getPOSTorGETValue("last_name"); echo "Your First Name is: " . $first_name . "<br>"; echo "Your Last Name is: " . $last_name . "<br>"; ?> </body> </html>Example Form Output
<? echo "<?xml version=\"1.0\"?>\n"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>File Upload Test</title> </head> <body> <h1>File Upload Test</h1> <? ini_set('display_errors', true); ini_set('display_startup_errors', true); error_reporting(E_ALL); // Limit what people can upload for security reasons $allowed_mime_types = array("video/3gpp"=>"3gp", "audio/x-wav"=>"wav", "video/mp4"=>"mp4", "video/3gpp2"=>"3g2", "video/mpeg"=>"mpg", "video/quicktime"=>"mov", "video/x-quicktime"=>"mov", "video/x-msvideo"=>"avi", "image/jpg"=>"jpg", "image/jpeg"=>"jpg", "image/pjpeg"=>"jpg", "image/png"=>"png", "audio/vnd.wave"=>"wav" ); // Make sure form was submitted if (isset($_POST['form_submitted']) && $_POST['form_submitted'] == "true") { // Check the mime type $allowed_types = array_keys($allowed_mime_types); $allowed = false; if (isset($_FILES['bytes']['type'])) { for ($i = 0; $i < sizeof($allowed_types) && !$allowed; $i++) { if (strstr($_FILES['bytes']['type'], $allowed_types[$i])) { $allowed = true; } } // If the mime type is good, save it.. if ($allowed) { $uploadfilename = time() . "_" . rand(1000,9999) . "_" . basename($_FILES['bytes']['name']); // Make sure apache can write to this folder $uploaddir = '/home/sve204/public_html/ppm_summer08/uploads/'; $uploadfile = $uploaddir . $uploadfilename; $uploadrelativefile = 'http://itp.nyu.edu/~sve204/ppm_summer08/uploads/' . $uploadfilename; if (move_uploaded_file($_FILES['bytes']['tmp_name'], $uploadfile)) { // Make sure the file isn't executable and you can delete it if you need chmod($uploadfile, 0666); $subject = ""; $message_text = ""; if (isset($_POST['subject'])) { $subject = $_POST['subject']; } if (isset($_POST['message_text'])) { $message_text = $_POST['message_text']; } // Tell the user echo "<p>Success <br /> <a href=\"" . $uploadrelativefile . "\">" . $uploadrelativefile . "</a></p>"; } else { echo "<p>Error on upload...! Here is some debugging info:</p>"; var_dump($_FILES); } } else { echo "<p>Type not allowed...! Here is some debugging info:</p>"; var_dump($_FILES); } } else { echo "<p>Strange, file type not sent by browser...! Here is some debugging info:</p>"; var_dump($_FILES); } } else { ?> <form enctype="multipart/form-data" method="post" action="upload.php"> <p> Title: <input type="text" name="subject" /><br /> Description: <input type="text" name="message_text" /><br /> <input type="file" name="bytes" /> <input type="hidden" name="form_submitted" value="true" /> <br /> <input type="submit" name="submit" value="submit" /> </p> </form> <? } ?> </body> </html>Permissions
include("phpBlip.php"); $phpBlip = new phpBlip();The first call includes the phpBlip class definition and related files. The second actually creates an object out of the class. This object is what can be used to query the blip site.
function find_posts($userid = null, $search = null, $explicit = false, $language_code = "en", $category = null, $license = null, $has_media = 1)
$results = $phpBlip->find_posts(); for ($i = 0; $i < sizeof($results); $i++) { print_r($results[$i]); }
$results = $phpBlip->find_posts(null,"cats"); for ($i = 0; $i < sizeof($results); $i++) { print_r($results[$i]); }
print_r($phpBlip->find_post($some_post_id));
$vids = $phpBlip->find_posts(null, "test"); for ($i = 0; $i < sizeof($vids); $i++) { $current_video = $phpBlip->find_post($vids[$i]["id"]); for ($m = 0; $m < sizeof($current_video['media']); $m++) { if ($current_video['media'][$m]['link_type'] == 'video/x-flv') { ?> <a href="http://itp.nyu.edu/~sve204/ppm_spring07/player.php?m=<?php echo $current_video['media'][$m]['link_href'] ?>"><? echo $current_video['title'] ?></a> <br><br> <? } } }