Jump to content

Graphic display whilst FTP running/loading

- - - - -

  • Please log in to reply
2 replies to this topic

#1
wendyb

wendyb

    Newbie

  • Members
  • Pip
  • 1 posts
Hi,
Would appreciate some help as to why this isn't displaying the graphic whilst running the ftp stuff. Take the ftp stuff out and works as expected.

<?PHP
ob_start();
?>
<div id='runftp'>
<img src="./images1/ajax-loader.gif" width="50" height="50" alt="Loading ... Please wait... " />
Loading
</div>
<?PHP
ob_end_flush();

$ftp_server="xx.xx.xx.xx";
$ftp_username="yyyyyyy";
$ftp_password="zzzzzzz";

// get folder information
$ch_names = array();

$conn = ftp_connect($ftp_server);
ftp_login($conn,$ftp_username,$ftp_password);

$ch_names=ftp_nlist($conn,".");
$i = 0;
while ($i < count($ch_names)) {
$file_count[$i]=ftp_nlist($conn,"/".$ch_names[$i]."/*.m*");
++$i;
}

ftp_close($conn);
?>
<script language="javascript">
runftp.style.display="none";
</script>

Many thanks

WB

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
The whole page must be processed before it is sent to the client, you must come up with your own way to query if that operation is done, i.e. asynchronous javascript (ajax).
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
Yes, PHP is a server-side language, and so all the PHP directives in your file have to be executed and processed before the page actually shows up in your browser.

To achieve what you're asking, you would have to put all of this code into a separate file:

$ftp_server="xx.xx.xx.xx";

$ftp_username="yyyyyyy";

$ftp_password="zzzzzzz";


// get folder information

$ch_names = array();


$conn = ftp_connect($ftp_server);

ftp_login($conn,$ftp_username,$ftp_password);


$ch_names=ftp_nlist($conn,".");

$i = 0;

while ($i < count($ch_names)) {

$file_count[$i]=ftp_nlist($conn,"/".$ch_names[$i]."/*.m*");

++$i;

}


ftp_close($conn);

And then make a call to this new file asynchronously using javascript (as Alex mentioned: AJAX).
The jQuery library has convenient methods that can be used to send requests to files asynchronously - check it out




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users