Page 1 of 1
PHP upload (get file size)
Posted: Tue Jun 20, 2006 10:17 pm
by tristanlee85
I'm trying to develop a pure PHP script to upload files using a progress bar as well. Everything else I find online is PHP with CGI or Java or C. I think I can get it to work if I can find 2 variables: the size of the file that's being uploaded and the size of the file as it is being uploaded (posted). I know how to read the filesize once it has already been uploaded, but can you read the total size before the file begins upload as well as read the size as the file is being posted?
Maybe a script like this has already been created that someone wouldn't mind directing me to.
Posted: Tue Jun 20, 2006 10:31 pm
by Luke
Sounds like AJAX is your solution, but don't ask me how to use ajax... I'm just getting started with it.
Posted: Tue Jun 20, 2006 10:36 pm
by tristanlee85
I was reading that too, but I'm making this script for a server that I'm not hosting so I'm not exactly sure what features are available. I would think you should be able to read the number of bytes uploaded because when uploading a file in PHP, the file is always stored in a temporary directory before actually moved to the designated upload directory, correct?
Posted: Tue Jun 20, 2006 11:20 pm
by Luke
The problem is that php is server-side... meaning a status bar would require about 100 page refreshes in order for the bar to "MOVE" if it's even possible. "MOVEMENT" on the screen requires something client-side.
Posted: Sun Jun 25, 2006 2:09 pm
by tristanlee85
So I've been checking out FileChucker. It's a single CGI script and I uses AJAX. Now, my question is: is AJAX a feature built into web browsers or is it an extension for the server-side? The reason I ask is because when I use this demo version, the files upload and all, but the progress meter doesn't move. After the file uploads it gives me my average upload speed, but just doesn't show the progress meter during upload. When I try the online version on their site, the progress bar works. I was thinking maybe this is because I don't have AJAX on my server...? I really have no idea what AJAX is. I've been trying to do research, but all I'm finding is information on AJAX.NET, and those DLL files won't work to well on FC5.
Posted: Sun Jun 25, 2006 2:15 pm
by Charles256
ajax is a combination of PHP and javascript.
Posted: Sun Jun 25, 2006 2:30 pm
by tristanlee85
So it's client-side then? It depends on their browser?
Posted: Sun Jun 25, 2006 2:36 pm
by Charles256
it's a combination of client and server,and yes, if jscript is not enabled hten no luck

Posted: Sun Jun 25, 2006 2:43 pm
by tristanlee85
So I guess my main question is, how do I know if my server supports AJAX? PHP works. Javascript works. Is that all that matters?
Posted: Sun Jun 25, 2006 2:53 pm
by Christopher
Any server will support Ajax because it is a client side technology. Ajax just mean communicating with a server via XMLHttpRequest or frames -- rather than GET/POST.
The problem with monitoring uploads with PHP is that there is no build-in provision for getting the name of the temporary upload file until the upload is complete. So no monitoring is possible. There is a patch to PHP that provides this functionality. Other languages such as Java and Perl have this capability so are frequently used in conjunction with PHP upload scripts. There are a couple of Perl solutions available.