PHP upload (get file size)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

PHP upload (get file size)

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Sounds like AJAX is your solution, but don't ask me how to use ajax... I'm just getting started with it.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post 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?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

ajax is a combination of PHP and javascript.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

So it's client-side then? It depends on their browser?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

it's a combination of client and server,and yes, if jscript is not enabled hten no luck :-D
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply