| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Oct 2006 Location: http://akshayjain.org
Posts: 2,830
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP help needed hi i am trying to fopen a file which is 20mb in size. i want fopen to only get the first 100kb or so from the file and ignore the rest. i do not want to even download the rest of the file. (saving bandwidth) is it possible? please tell me what commands to use for that thanks |
| |
| | #2 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I am not 100% sure but I would suspect using fgets could do it:- http://uk.php.net/fgets you would need to specify the length you wish to read in the 2nd parameter.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #4 (permalink) | ||||
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | ||||
| |
| | #5 (permalink) | ||||
| NamePros Regular Join Date: Oct 2006
Posts: 963
![]() ![]() |
????: NamePros.com http://www.namepros.com/programming/390934-php-help-needed.html fgets might not work by the way, as it only works with textfiles and probably does not support partial downloads. | ||||
| |
| | #6 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | read the manual for fgets. Part of its functionality is to read the first x amount of bytes from a file. And what makes you say fgets only works with txt files? Any file that contains ASCII can be read by fgets. In fact if you read the documentation for fsockopen you will see they have used it to read the contents of a webpage (whilst only reading 128 bytes at a time). http://uk.php.net/manual/en/function.fsockopen.php
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #7 (permalink) | ||||||||
| NamePros Regular Join Date: Oct 2006
Posts: 963
![]() ![]() |
| ||||||||
| |
| | #8 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP is not about having handed to you on a plate you do actually have to do stuff (and think of things) for yourself as well. A pseudo piece of code (working from the fsockopen example) could be:- PHP Code: If he needs to know for sure that it works then that is what testing is for.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #9 (permalink) |
| Senior Member Join Date: Aug 2005 Location: East Yorkshire, England
Posts: 2,689
![]() ![]() ![]() ![]() ![]() ![]() ![]() | I suppose you could use fgetc() or fread(), to avoid the newline problem PHP Code: PHP Code: |
| |
| | #10 (permalink) | ||||||||
| NamePros Regular Join Date: Oct 2006
Posts: 963
![]() ![]() |
| ||||||||
| |