CaTaLinU Posted June 19, 2012 Share Posted June 19, 2012 Can someone help me with some code that will shows what is between row x and y with ftp functions from a file and from a diferent host with connection with user and password to that external host ... ? Thx .. Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/ Share on other sites More sharing options...
btherl Posted June 19, 2012 Share Posted June 19, 2012 Are you going to fetch the entire file and then find rows x to y? Or do you want to fetch only rows x to y? Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355055 Share on other sites More sharing options...
CaTaLinU Posted June 19, 2012 Author Share Posted June 19, 2012 just to show what is between line x and y from a file.txt Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355076 Share on other sites More sharing options...
CaTaLinU Posted June 19, 2012 Author Share Posted June 19, 2012 a little help please ? Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355243 Share on other sites More sharing options...
.josh Posted June 19, 2012 Share Posted June 19, 2012 You cannot do this with the ftp commands (except possibly by using file manipulation commands like fopen/fseek/fread through ftp_raw, if permissions allow, which most likely not..also, I'm not entirely sure you can actually use those commands). You will have to retrieve the file as a whole, and then search through it. You may (with proper permissions local and remotely) be able to do it with sockets though with limitations. (Sockets would in theory allow you to run arbitrary shell commands on the remote server, so for instance you could run php remotely and use the file reading functions, or use shell commands). Either way... None of the file reading commands (whether done locally or through a socket allows you to just grab x through y lines unless the lines are by convention all a fixed number of char length (padded if shorter), and then you can use fseek to jump to the line based on $x * $length. If the lines are not fixed length, you will have to either make a loop and just continue until $x (and then break at line $y), or put the file in its entirety into an array (like with file - not advisable unless the filesize is always expected to be relatively small). edit: nevermind looks like you actually can't even use ftp_exec or ftp_raw. ftp_exec only returns a status code or false, no info, so even if the remote server allowed it, it would be useless. ftp_raw only (assuming permissions allow for it) only do raw ftp commands, not php commands! Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355247 Share on other sites More sharing options...
btherl Posted June 19, 2012 Share Posted June 19, 2012 In summary, no it can't be done If you can describe the problem you are trying to solve we may be able to suggest an alternative solution. Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355274 Share on other sites More sharing options...
CaTaLinU Posted June 20, 2012 Author Share Posted June 20, 2012 I have done this code , and it works perfectly with little bugs ... if i set to read the lines from 0 to 20 , on the page it shows that lines but if i set to show the lines from 20 to 40 , it shows the lines from 0 to 20 on page ... that is the bug or the error... or if i set to 40 to 80 it shows the lines from 0 to 40 because 80 - 40 = 40 40 - 20 = 20 .... $handle = fopen("file.txt", "r"); $lenght_parameter = "9999999"; $ic = 20; $ic_max = 40; // stops after this number of rows while (!feof($handle) && ++$ic<=$ic_max) { $buffer = fgets($handle, $lenght_parameter); echo $buffer."<br>"; } fclose($handle); Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1355367 Share on other sites More sharing options...
btherl Posted June 24, 2012 Share Posted June 24, 2012 You need to skip the first lines for that to work. That means you need a different variable to remember which line you are on, AND the start line and end line. You would skip lines while $i <= $ic, then print lines while $i <= $ic_max. Quote Link to comment https://forums.phpfreaks.com/topic/264416-ftp-php-show-the-rows-from-line-x-to-y/#findComment-1356550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.