Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Gmail - Add Attachments - Reverse Engineering

Reply
Thread Tools

Gmail - Add Attachments - Reverse Engineering

 
 
JavaScriptRocks
Guest
Posts: n/a
 
      08-03-2005
I've been trying to imitate / reverse engineer the add attachment
feature in gmail composer. I managed to do it to say about 80% but its
giving me trouble in IE on WinXP-Sp2. I am using PHP to do the upload.
It works well on Firefox/DeerPark, but in IE, the file selected just
vanishes. You can verify it by commenting the lines marked "//IE
Trouble". Commenting those lines will remove IE specific code.

Please someone help me.

_____________________________________
Here is the code
Tab Size: 8
-------------------------------------
<?
include_once('../modules/file_upload/lib_upload.php');
?>
<script language="JavaScript">

function Table_AddRow(tblName, pos) {
if(typeof(pos) == 'undefined')
pos = '_LAST_';

var tbl = document.getElementById(tblName);
switch(pos)
{
case '_LAST_':
pos = tbl.rows.length;
default:
pos = parseInt(pos, 10);
if(isNaN(pos))
{
pos = 0;
}
else if (pos > tbl.rows.length)
{
pos = tbl.rows.length;
}
}

var today = new Date();
var rowID = tblName + today.getTime() + tbl.rows.length;

var row = tbl.insertRow(pos);
if(document.all) row.style.display = 'none'; //IE Trouble
var cellRight = row.insertCell(row.length);
cellRight.setAttribute('id', rowID);

var el = document.createElement('input');
el.setAttribute('type', 'FILE');
el.setAttribute('name', 'upload_files[]');
if(document.all) el.style.display = 'none'; //IE Trouble
cellRight.appendChild(el);


if(document.all) //IE Trouble
{ //IE Trouble
el.click(); //IE Trouble
if(el.value == '') //IE Trouble
{ //IE Trouble
DeleteCurRow(row); //IE Trouble
} //IE Trouble
else //IE Trouble
{ //IE Trouble
row.style.display = ''; //IE Trouble
var fn = document.createElement("strong"); //IE Trouble
fn.innerHTML = el.value; //IE Trouble
cellRight.appendChild(fn); //IE Trouble
} //IE Trouble
} //IE Trouble
var spc = document.createElement("span");
spc.innerHTML = "&nbsp;";
cellRight.appendChild(spc);

var aa = document.createElement("a");
aa.setAttribute('href', 'javascript:;');
var clickName = new
Function("Table_DeleteRowByID('"+tblName+"','"+row ID+"')");
aa.onclick = clickName;
aa.innerHTML = "remove";
cellRight.appendChild(aa);
}

function Table_DeleteRow(x)
{
while (x.tagName.toLowerCase() !='tr')
{
if(x.parentElement)
x=x.parentElement;
else if(x.parentNode)
x=x.parentNode;
else
return;
}
var rowNum=x.rowIndex;
while (x.tagName.toLowerCase() !='table')
{
if(x.parentElement)
x=x.parentElement;
else if(x.parentNode)
x=x.parentNode;
else
return;
}
x.deleteRow(rowNum);
}

function Table_DeleteRowByIndex(tblName, row)
{
var tbl = document.getElementById(tblName);
x.deleteRow(row);
}

function Table_DeleteRowByID(tblName, rowID)
{
var tbl = document.getElementById(tblName);
var row = document.getElementById(rowID);
while (row.tagName.toLowerCase() !='tr')
{
if(row.parentElement)
row = row.parentElement;
else if(row.parentNode)
row = row.parentNode;
else
return;
}
var rowNum = row.rowIndex;
tbl.deleteRow(rowNum);
}

</script>

<form method="post" enctype="multipart/form-data">
<table id="tblSample" border="0" cellspacing="2" cellpadding="2">
<tr id="tblSample_row0">
<td><a href="javascript:;" onClick="Table_AddRow('tblSample', 0);
return false;">Add File</a></td>
</tr></table><input type="hidden" name="MAX_FILE_SIZE"
value="512000"><input type=submit>
</form>

<?php
if($REQUEST_METHOD == "POST")
{
$newNames = array();
if(($newFile = UploadFile('upload_files', '.', 1, $newNames,
array('application/x-zip-compressed', 'application/zip'))) === false)
{
?><font color=red><b>Upload of <?= sizeof($APP_ERR)?> file(s)
failed.</font><br><strong>Error: </strong><? print_r($APP_ERR)?><?
}
else
{
?><font color=green><b><?= sizeof($newNames)?> file(s)
uploaded.<br></font>&nbsp;&nbsp;&nbsp;New filename: <?
print_r($newNames) ?><?
}
}

?>

________________________________________
lib_upload.php (skeleton)
----------------------------------------
function UploadFile($name, $path, $mandatory = 0,
&$newName, $mimeAllowed = array())
{
return ($ERR === true? false: $newName);
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call for Papers: World Congress on Engineering WCE 2007 (IAENG conferences with Engineering Letters) imecs__2007@iaeng.org Java 0 12-19-2006 06:51 AM
CFP: Special Issue on Web Engineering (The journal Engineering Letters) imecs_2006@iaeng.org Java 0 01-07-2006 04:48 AM
Gmail - dynamic Add Attachment - Reverse Engineering JavaScriptRocks Javascript 3 08-07-2005 12:23 PM
Reverse engineering an EDIF file? Rastislav Struharik VHDL 8 01-02-2004 01:57 PM



Advertisments