svn: /pear/packages/HTTP_Request2/trunk/ Request2/MultipartBody.php docs/examples/upload-rapidshare.php package.xml

From: Date: Fri, 14 Aug 2009 15:22:52 +0000
Subject: svn: /pear/packages/HTTP_Request2/trunk/ Request2/MultipartBody.php docs/examples/upload-rapidshare.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-57139@lists.php.net to get a copy of this message
avb Fri, 14 Aug 2009 15:22:52 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=287306 Log: First usage example for HTTP_Request2: uploading a file to rapidshare.com Also changed multipart/form-data boundary generation to work with (incorrect) rapidshare parsing algorithm Changed paths: _U pear/packages/HTTP_Request2/trunk/ U pear/packages/HTTP_Request2/trunk/Request2/MultipartBody.php A pear/packages/HTTP_Request2/trunk/docs/ A pear/packages/HTTP_Request2/trunk/docs/examples/ A pear/packages/HTTP_Request2/trunk/docs/examples/upload-rapidshare.php U pear/packages/HTTP_Request2/trunk/package.xml Property changes on: pear/packages/HTTP_Request2/trunk ___________________________________________________________________ Added: svn:ignore + .project Modified: pear/packages/HTTP_Request2/trunk/Request2/MultipartBody.php =================================================================== --- pear/packages/HTTP_Request2/trunk/Request2/MultipartBody.php 2009-08-14 14:59:05 UTC (rev 287305) +++ pear/packages/HTTP_Request2/trunk/Request2/MultipartBody.php 2009-08-14 15:22:52 UTC (rev 287306) @@ -152,7 +152,7 @@ public function getBoundary() { if (empty($this->_boundary)) { - $this->_boundary = 'PEAR-HTTP_Request2-' . md5(microtime()); + $this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime()); } return $this->_boundary; } Added: pear/packages/HTTP_Request2/trunk/docs/examples/upload-rapidshare.php =================================================================== --- pear/packages/HTTP_Request2/trunk/docs/examples/upload-rapidshare.php (rev 0) +++ pear/packages/HTTP_Request2/trunk/docs/examples/upload-rapidshare.php 2009-08-14 15:22:52 UTC (rev 287306) @@ -0,0 +1,51 @@ +<?php +/** + * Usage example for HTTP_Request2 package: uploading a file to rapidshare.com + * + * $Id$ + */ + +require_once 'HTTP/Request2.php'; + +// You'll probably want to change this +$filename = '/etc/passwd'; + +try { + $request = new HTTP_Request2( + 'http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1' + ); + $server = $request->send()->getBody(); + if (!preg_match('/^(\\d+)$/', $server)) { + throw new Exception("Invalid upload server: {$server}"); + } + + if (false === ($hash = @md5_file($filename))) { + throw new Exception("Cannot calculate MD5 hash of '{$filename}'"); + } + + $uploader = new HTTP_Request2( + "http://rs{$server}l3.rapidshare.com/cgi-bin/upload.cgi", + HTTP_Request2::METHOD_POST + ); + $uploader->addUpload('filecontent', $filename); + $uploader->addPostParameter('rsapi_v1', '1'); + + $response = $uploader->send()->getBody(); + if (!preg_match_all('/^(File[^=]+)=(.+)$/m', $response, $m, PREG_SET_ORDER)) { + throw new Exception("Invalid response: {$response}"); + } + $rspAry = array(); + foreach ($m as $item) { + $rspAry[$item[1]] = $item[2]; + } + if (empty($rspAry['File1.4'])) { + throw new Exception("MD5 hash data not found in response"); + } elseif ($hash != strtolower($rspAry['File1.4'])) { + throw new Exception("Upload failed, local MD5 is {$hash}, uploaded MD5 is {$rspAry['File1.4']}"); + } + echo "Upload succeeded\nDownload link: {$rspAry['File1.1']}\nDelete link: {$rspAry['File1.2']}\n"; + +} catch (Exception $e) { + echo "Error: " . $e->getMessage(); +} +?> Property changes on: pear/packages/HTTP_Request2/trunk/docs/examples/upload-rapidshare.php ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: pear/packages/HTTP_Request2/trunk/package.xml =================================================================== --- pear/packages/HTTP_Request2/trunk/package.xml 2009-08-14 14:59:05 UTC (rev 287305) +++ pear/packages/HTTP_Request2/trunk/package.xml 2009-08-14 15:22:52 UTC (rev 287306) @@ -101,6 +101,9 @@ <file role="test" name="ObserverTest.php" /> <file role="test" name="Request2Test.php" /> </dir> + <dir name="docs/examples"> + <file role="doc" name="upload-rapidshare.php" /> + </dir> <file role="php" name="Request2.php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> @@ -130,6 +133,9 @@ <extension> <name>zlib</name> </extension> + <extension> + <name>openssl</name> + </extension> </optional> </dependencies> <phprelease />

« previous php.pear.cvs (#57139) next »