How to get number of uploaded bytes in php

oracle

New Member
Messages
430
Reaction score
0
Points
0
Hello All,

I know there exists a few upload progress showing scripts, but I wanted to know for knowledge sake how do I get to know how many bytes have been uploaded till now.

move_uploaded_file($FileTemp,$FileUploadLocation)

after giving this command how do I know how many bytes have been uploaded till now ?
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
He's not asking about information about the posted file, he wants some sort of thread-like system that tracks how many bytes have already been uploaded...

But why would you want it? I don't think it's possible to do something like that in php, but perhaps we can find a way around the problem?
 

bugfinder

Retired
Messages
2,260
Reaction score
0
Points
0
sure it is, if you look at the thing I posted you sum up the total bytes....
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
I think you got it wrong.... I want to show a upload progress meter...

I know there are many out there in the market but I want to build my own custom one. As I think it isnt a big issue in making one, so I dont consider it as reinventing the wheel :)

Your given link doesnt show anything which can show something like 20% file is upload etc etc

I want to show user % upload sort of thingy.

Imoracle
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Yeah surely it will be ajax, but then again you have posted an already made script for the same. I just want to know the method in PHP through which I can get the % upload and then I know how to use that.

The site you gave is giving me 501 error , can you attach the codes if you have them?
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
1
Points
0
Well... Now its giving me the same error...
Anyway, you could look at the pre-made scripts' code and see how its done.
 

mattura

Member
Messages
570
Reaction score
2
Points
18
It's not that simple...in fact it's not simple at all!
You need to create an invisible iframe, and send the upload to that. Within the iframe, PHP code polls itself with the current filesize(), taken from the *.tmp file in the temp upload directory.
You then use javascript to get what's in the iframe, and turn it into something useful (like x%, or a variable width bar) to display.

Something similar is done here:
http://indiza.com/alsanan/index.php...20y%20sin%20hackear%20el%20int%E9rprete%20PHP
Something slightly different is done (with ajax and a php patch) here:
http://bluga.net/projects/uploadProgressMeter/

Basically it's a beast of a problem, and these solutions are still not reliable (eg if two people upload something simultaneously)
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Yeah I know the process of how exactly it is done, just that I am unable to figure out how to get the size of remaining upload file....

This is what I am unable to figure out. If someone can help me with this, I will be able to figure out the rest easily.

Lemme look at the first link by you, though its not in english.

2nd one needs a patched version and I dont think we can do that here with shared hosting.
 

VPmase

New Member
Messages
914
Reaction score
1
Points
0
Well there is always the option to code it in Flash AS2/3 if you know how/have Flash.
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
unfortunately I dont :(

Also I dont want to put myself in danger, when a user tried to upload a file and his browser doesnt have flash.... :(

This is quite disappointing that we just cant do anything about it :(
 
T

themasterrocker

Guest
you could always look at the file bytes to the right of the file name.
 
Last edited by a moderator:

oracle

New Member
Messages
430
Reaction score
0
Points
0
I didnt get you what do you mean by your post ?? Can you elaborate ?
 
T

themasterrocker

Guest
next to the file name it says how many bytes under the "size" of the file. Take this example from Cpannel.

sizevq1.png


Sorry about the rubbish quility.
 
Last edited by a moderator:

oracle

New Member
Messages
430
Reaction score
0
Points
0
I guess you didnt get my point correctly or infact i wasnt able to put it clearly.

I dont want the file size of the final upload file, but i need the file size of intermediate file, while uploading.

This file usually lies in the tmp directory.
 

VPmase

New Member
Messages
914
Reaction score
1
Points
0
Ok! I was looking through an AJAX upload script and what it did was open the temp file up and get its size.

PHP:
//Class to store read info
class ReadStatus{
	var $is_dir_error = 0;
	var $open_dir_error = 0;
	var $active = 0;
	var $uploaded_files = 0;
	var $bytes_uploaded = 0;
}

// Return the current size of the $_GET['temp_dir_sid'] - flength file size.
function GetBytesRead($temp_dir, $upload_id){
	$read_status = new ReadStatus;
	$temp_upload_dir = $temp_dir . $upload_id . '.dir';
	$flength_file = $temp_dir . $upload_id . '.dir/' . $upload_id . '.flength';

	if(is_dir($temp_upload_dir) && file_exists($flength_file)){
		if($handle = opendir($temp_upload_dir)){
			while(false !== ($file_name = readdir($handle))){
				if(($file_name != '.') && ($file_name != '..') && ($file_name != $flength_file)){
					$read_status->bytes_uploaded += filesize($temp_upload_dir . '/' . $file_name);
					$read_status->uploaded_files++;
				}
			}
			closedir($handle);

			$read_status->active = 1;

			if($read_status->uploaded_files > 0){ $read_status->uploaded_files -= 1; }
		}
		else{ $read_status->open_dir_error = 1; }
	}
	else{ $read_status->is_dir_error = 1; }

	return $read_status;
}
Taken from Uber Uploader (uber_get_progress.php).
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Thanks a lot, let me try this out and I will get back to you
 

oscetips

New Member
Messages
26
Reaction score
0
Points
0
PHP doesnt allow access to file size during uploads. The work around is to use a perl script for uploading and use a looping ajax/JS script to obtain the file size of the upload.. I like you am working on a customised script and am happy to post it once the problems are ironed out.
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Yaa i kindaa have come across a perl script on net an hour back :)

Will try out myself and if it works i wil post it here
 
Top