[xiph-commits] r15085 - in trunk/oggPusher: . Server firefox-extension/chrome/content
nithin at svn.xiph.org
nithin at svn.xiph.org
Sat Jun 28 21:31:07 PDT 2008
Author: nithin
Date: 2008-06-28 21:31:06 -0700 (Sat, 28 Jun 2008)
New Revision: 15085
Added:
trunk/oggPusher/Server/post.php
Modified:
trunk/oggPusher/Server/README
trunk/oggPusher/firefox-extension/chrome/content/op_Window.js
trunk/oggPusher/oggPusher.xpi
Log:
Changes in Upload function to accomdate for the reponse body still not functional
Modified: trunk/oggPusher/Server/README
===================================================================
--- trunk/oggPusher/Server/README 2008-06-29 04:02:17 UTC (rev 15084)
+++ trunk/oggPusher/Server/README 2008-06-29 04:31:06 UTC (rev 15085)
@@ -1,2 +1,5 @@
Presently the URL for the upload is hardcoded as
-http://localhost/upload.php
+http://www.it.iitb.ac.in/~nithind/post.php
+
+the files are supposed to be created in uploads dir in my home directory
+
Added: trunk/oggPusher/Server/post.php
===================================================================
--- trunk/oggPusher/Server/post.php (rev 0)
+++ trunk/oggPusher/Server/post.php 2008-06-29 04:31:06 UTC (rev 15085)
@@ -0,0 +1,33 @@
+<?
+print_r($_FILES);
+?>
+<hr>
+<?
+print_r($_POST);
+
+$fpath = "/var/www/uploads/";
+$file_name = $fpath . basename($_FILES{'myfile'}{'name'});
+echo $file_name;
+
+// move (actually just rename) the temporary file to the real name
+move_uploaded_file ( $_FILES{'myfile'}{'tmp_name'}, $file_name );
+
+// convert the uploaded file back to binary
+
+// javascript "escape" does not encode the plus sign "+", but "urldecode"
+// in PHP make a space " ". So replace any "+" in the file with %2B first
+
+$filename = $file_name;
+$handle = fopen($filename, "r");
+$contents = fread($handle, filesize($filename));
+fclose($handle);
+
+$contents = preg_replace("/\+/", "%2B", $contents);
+
+$handle = fopen($filename, "w");
+fwrite($handle, urldecode($contents));
+fclose($handle);
+
+?>
+
+
Modified: trunk/oggPusher/firefox-extension/chrome/content/op_Window.js
===================================================================
--- trunk/oggPusher/firefox-extension/chrome/content/op_Window.js 2008-06-29 04:02:17 UTC (rev 15084)
+++ trunk/oggPusher/firefox-extension/chrome/content/op_Window.js 2008-06-29 04:31:06 UTC (rev 15085)
@@ -38,7 +38,6 @@
},
uploadFile:function()
{
- try{
var filePath = document.getElementById("file-path").value;
var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
@@ -46,16 +45,32 @@
fstream.init(file, 1, 1, Components.interfaces.nsIFileInputStream.CLOSE_ON_EOF);
var bstream = Components.classes['@mozilla.org/network/buffered-input-stream;1'].createInstance(Components.interfaces.nsIBufferedInputStream);
bstream.init(fstream, 4096);
+ var binary = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
+ binary.setInputStream(fstream);
xhr = new XMLHttpRequest();
- }
- catch(err){
- alert(err);
- return;
- }
+
+
+
+ var boundaryString = 'capitano';
+ var boundary = '--' + boundaryString;
+ var requestbody = boundary + '\n'
+ + 'content-Dispostion: form-data; name="fileInput"; filename="' + filePath+ '"'+'\n'
+ +'Content-Type: application/octet-stream'+'\n'
+ +'Content-Transfer-Encoding: binary'+'\n'
+ + '\n'
+ + escape(binary.readBytes(binary.available()))
+ + '\n'
+ + boundary;
+
+
+
+
xhr.onreadystatechange = function() { if(this.readyState == 4) {alert(this.responseText)}}
- xhr.open("POST", "http://localhost/upload.php", true);
- xhr.setRequestHeader('Content-Type', 'application/octet-stream');
- xhr.send(bstream);
+ xhr.open("POST", "http://www.it.iitb.ac.in/~nithind/post.php", true);
+ xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=\""+ boundaryString + "\"");
+ //xhr.setRequestHeader("Connection", "close");
+ xhr.setRequestHeader("Content-length", requestbody.length);
+ xhr.send(requestbody);
}
Modified: trunk/oggPusher/oggPusher.xpi
===================================================================
(Binary files differ)
More information about the commits
mailing list