Page 2 of 2

Posted: Sat Sep 03, 2005 3:44 pm
by josh
Well my method does NOT involve submitting the file to the iframe, build your form like normal, except instead of placing a submit button at the end place a normal button and have it call javascript:

Code: Select all

<script>
<!--
// Toggle your div layer's visibility or whatever you want to do

// Now submit your form to begin uploading the file
document.myForm.submit();

// You will generate a token from php and put it in a hidden form field, this way you can associate the RPC request with the right user
token = document.myForm.token;

// Your RPC call
document.myIFrame.location = 'http://example.com/rpc.php?token=' + token;

function updateStatus(msg) {
    // This code will output msg to the div layer
}
-->
</script>
rpc.php would accept the token, it would lookup the bytes uploaded so far and would output some javascript to
1) make a parent call to the page where you are uploading the file from, calling the updateStatus() command, this call will output status information to the div layer, (for example it could output the bytes uploaded so far)
2) it would output a meta refresh tag to refresh itself in 1 second (when refreshing it would also re-send the token)


As for getting rpc.php to stat the filesize of the file you are uploading, you are on your own on that one.

Once you get the above working you could use some other method, like feyd suggested for obtaining the TOTAL file size, from there you could dispaly as detailed information such as upload progress.

Good luck, and if you get this thing working let me know!

Posted: Sat Sep 03, 2005 3:56 pm
by Fourtet
If I get this thing working with PHP standard I think I'll be famous. :lol:

Seriously, your logic is great I just don't think it's possible. I think when you submit the form the file uploads, now you can return the tmp name to the callback from php, but once you have the tmp name and send it back to php there is no way in php to get information about the process of that file upload.

Posted: Sat Sep 03, 2005 4:06 pm
by josh
An option always is just use a little bit of perl. Sort of a "perl-PHP hybrid uploader"

Posted: Sat Sep 03, 2005 4:07 pm
by s.dot
I've FIGURED IT OUT.

A PURE PHP FILE UPLOAD PROGRESS BAR.

I just choose not to share.

Posted: Sat Sep 03, 2005 4:07 pm
by Fourtet
Perl is evil. :(

May have to resort to it though, will see how it goes. Blast, got to set it up on apache now. :roll:

Thanks for your advice jsh.

Posted: Sat Sep 03, 2005 6:54 pm
by bokehman
It is not possible solely with PHP. Your best bet is the javascript option. I have posted a demo here. If you like it all you need to do is copy the source. http://myhomewebserver.co.uk/loading

Posted: Sat Sep 03, 2005 7:21 pm
by Fourtet
Boke it does nothing server side. Surely the whole point of the thread is that it would be useful if we could offer download time /percentage stats etc.


I've been trying to use the excellent perl/php hybrid code at raitha.com - and adapting it to use an embedded iframe instead of a pop up, it doesn't seem to work though, it creates the iframe on clicking submit but doesn't write the prog bar to it, but it works fine when using the pop up function.

Html

Code: Select all

<form  enctype="multipart/form-data" action="/cgi-bin/upload.cgi?sid=<? echo $sid; ?>" method="post">


<table border="0" cellpadding="10" align="center">
<tr><td width="35%" valign="top"><p>
Use this form to upload some files and check out the functionality of the uploader.
The total file size should be less than 5MB or it will be rejected. 
</p>
<p>If you use a
file that is too small the progress bar may not have enough time to display itself,
specially if you are on a high speed connection.
</p>
<table class="newboxTable">
	<tr><td class="newboxTitle"  align="center">Note</td></tr>
	<tr><td>
		The speed of upload has been throttled for the health of the server.
	</td></tr>
	</table>
</td>
<td  valign="top">
	<table border=0 align="left" cellpadding=3>
	<tr><td><input type="file" name="file[0]"></td></tr>
	<tr><td colspan=2 align="center">
		<input type="hidden" name="sessionid" value="<?= $sid ?>">
		<input type="button" value="Send" onClick="postIt();">
		<!-- uncomment the following to test with out the progress bar -->
		<!input type="submit" value="Send">
	</td></tr></table>
</td>
</tr></table>

</form>

<IFRAME id="iframe" SRC="" TITLE="The Famous Recipe">
</IFRAME>
JS

Code: Select all

function popUP(mypage, myname, w, h, scroll, titlebar)
{

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function postIt()
{

	if(check_types() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.forms[0].sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&sessionid=" + sid;

	//popUP(baseUrl,"Uploader",460,262,false,false);
	
		newi = document.createElement("iframe"); 
		newi.id = "newi";		
		document.body.appendChild(newi); 
		newi.src = baseUrl;
	
	document.forms[0].submit();
}

Posted: Thu Sep 08, 2005 11:26 pm
by josh
Kinda digging up an old thread, but what if you wrote a simple http server using PHP's socket support, and had that running (as a shell script, not cgi), you could have your little server listen on port 8080, then when you do your file uploads just set the action to "http://example.com:8080", then your PHP web server would just read the http request, therefore achieving raw header access!

Posted: Thu Sep 08, 2005 11:44 pm
by feyd
it could work, but you'd have to find a host that allows permanently loaded shell scripts ;) .. I don't remember many existing these days (that are open to the public)