Jump to content

[SOLVED] FTP progress?


next

Recommended Posts

How can i make a progress bar or a simple text tracking of what is being uploaded?

I currently have this code:

<?php
$server = '***';
$username = '***';
$password = '***';

$x = dir('S:\Accounting Scanning\LTD\2008\8724');
//if directory doesn't exist
if($x == false)
	exit();

//get all file names and store them in "uploads" array
while($f = $x->read()) {
	if(is_file($x->path . '\\' . $f) && $f != 'Thumbs.db')
		$uploads[] = $f;
}

$total_files = sizeof($uploads);

  	//FTP
try {
	//connect and login
	$fth = ftp_connect($server);
	ftp_login($fth, $username, $password);

	//change current directory
	ftp_chdir($fth, 'LTD');

	//if files were found in the directory, lst them and close the connection
	$files = ftp_nlist($fth, '.');
	if($files) {
		echo 'these files were found in LTD directory: <br />';
		echo '<ul>';

		foreach($files As $key => $file)
			echo '<li>'. $file .'</li>';

		echo '</ul>';
		ftp_close($fth);
		exit();
	}

	//if no files were found in the directory, proceed with upload
	foreach($uploads As $key => $file) {
		if(!ftp_put($fth, $file, $x->path . "\\$file", FTP_BINARY))
			$errors[] .= "<li>" . $x->path . "\\$file</li>";
		else {
			$i++;
			$left = $total_files - $i;
			echo "currently uploading $file ---------------- $left files left to upload.<br />";
		}
	}

	if($errors) {
		echo '<ul>';
			foreach($errors as $key => $error)
				echo $error;

		echo '</ul>';
	}

	ftp_close($fth);
}
catch(Exception $e) {
	echo $e->getMessage();
	exit();
}
?>

but this code displays my progress after all uploading is done, which is no good.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/117372-solved-ftp-progress/
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.