validate_sig()) { // Ok } else { die("Authentication Failed. Error is: $authObj->sig_validation_error"); } $url = 'http://photos.yahooapis.com/V3.0/uploadPhotos?caption0=Texas%20Capital&desc0=Not%20much%20to%20look%20at'; $url = $authObj->createAuthWSurl($url); if ($url === false) { die("Failed to create authenticated url. Error is: $authObj->access_credentials_error"); } else { // Ok } // Create standard multipart form post boundary $boundary = uniqid('------------------'); $MPboundary = '--'.$boundary; $endMPboundary = $MPboundary. '--'; // Create multipart form post per Yahoo! Photos and RFC 1867 // Fetch a photo (you could use a form upload for this) $picture0 = file_get_contents('http://www.ci.austin.tx.us/images/places/plimage19_sm.jpg'); // Create the multipart body. The name and filename are required but are just placeholders. $multipartbody=''; $multipartbody .= $MPboundary . "\r\n"; $multipartbody .= 'Content-Disposition: form-data; name="txcapital"; filename="texascapital.jpg"'. "\r\n"; $multipartbody .= 'Content-Type: image/jpeg'. "\r\n\r\n"; $multipartbody .= $picture0; $multipartbody .= "\r\n". $endMPboundary; // Do the POST // Number of seconds to wait until Yahoo! server responds $timeout = 15; $status = array(); $sockets = array(); $errno = null; $errstr = null; // Parse the URL into parameters for fsockopen $urlARR = parse_url($url); $path = $urlARR['path'].'?'.$urlARR['query']; $host = 'photos.yahooapis.com'; $port = 80; // Zero out the error variables $errno = null; $errstr = ''; // Open the connection to Yahoo $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); // Failed to open the URL if (!is_resource($fp)) { // fsockopen failed die('fsockopen call failed with error number ' . $errno . '.' . $errstr); } // Send an HTTP GET header and Host header if (!(fwrite($fp, 'POST '. $path .' HTTP/1.1' . "\r\n"))) { fclose($fp); die('Could not write POST to socket!'); } // Send Host header if (!(fwrite($fp, 'Host: ' . $host . "\r\n"))) { fclose($fp); die('Could not write Host to socket'); } // Send POST mime type if (!(fwrite($fp, 'Content-Type: multipart/form-data; boundary='.$boundary."\r\n"))) { fclose($fp); die('Could not write Content-type'); } // Send cookie if (!(fwrite($fp, 'Cookie: '. $authObj->cookie."\r\n"))) { fclose($fp); die('Could not write Cookie'); } // Send the length of POST args header if (!(fwrite($fp, 'Content-Length: '.strlen($multipartbody)."\r\n"))) { fclose($fp); die('Could not write Content-length'); } // Send close connection header if (!(fwrite($fp, 'Keep-Alive: 300'."\r\n"))) { fclose($fp); die('Could not write keep alive'); } // Send close connection header if (!(fwrite($fp, 'Connection: keep-alive'."\r\n\r\n"))) { fclose($fp); die('Could not write keep alive'); } // Send POST arguments if (!(fwrite($fp, $multipartbody))) { fclose($fp); die('Could not write postargs'); } // Block on the socket port, waiting for response from Yahoo if (function_exists('socket_set_timeout')) { @socket_set_timeout($fp, $timeout); socket_set_blocking($fp, true); } // Get the HTTP response code from Yahoo $line = fgets($fp , 1024); if ($line == false){ fclose($fp); die('Yahoo did not respond'); } // Parse and evaluate the HTTP status code // HTTP return code of 200 means success $status_code = array(); preg_match('/\d\d\d/', $line, $status_code); switch( $status_code[0] ) { case 200: // Success break; default: echo 'Your call to Yahoo Web Services returned an unexpected HTTP status of: ' . $status_code[0]. '
'; } // Find blank line between header and data do { $line = fgets($fp , 1024); if ($line == false) { fclose($fp); die('No data back from Yahoo.'); } if (strlen($line) < 3) { break; } } while (true); $xml=''; // Fetch the data from Yahoo while ($line = fread($fp, 8192)) { if ($line == false) { fclose($fp); die('Again no data back from Yahoo.'); } $xml .= $line; } fclose($fp); echo '

The XML below should contain information about your file upload. Check your Yahoo! Photos account for the photo!

'; // Output the XML echo htmlspecialchars($xml, ENT_QUOTES); } else { echo ''; echo ''; echo '

This will upload a small picture of the Texas State Capital to your Yahoo! Photos account

'; echo 'UPLOAD A PHOTO'; echo ''; echo ''; } ?>