| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | 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) |
| Senior Member | 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 |
| |
| | #3 (permalink) |
| NamePros Regular | Mentioning "download" I assume you dont talk about a local file, right? Do you want to access the beginning of the file?
__________________ Paris loves CityPics muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com -- Do not let others be treated this way! |
| |
| | #4 (permalink) | |
| Senior Member | Quote:
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | |
| |
| | #5 (permalink) | |
| NamePros Regular | Quote:
fgets might not work by the way, as it only works with textfiles and probably does not support partial downloads.
__________________ Paris loves CityPics muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com -- Do not let others be treated this way! | |
| |
| | #6 (permalink) |
| Senior Member | 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 | Quote:
Quote:
__________________ Paris loves CityPics muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com -- Do not let others be treated this way! | ||
| |
| | #8 (permalink) |
| Senior Member | 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) |
| Barru. | I suppose you could use fgetc() or fread(), to avoid the newline problem PHP Code: PHP Code:
__________________ |
| |
| | #10 (permalink) | ||
| NamePros Regular | Quote:
Quote:
__________________ Paris loves CityPics muov.com • qeww.com • sejz.com • viuo.com • vuav.com • wzeo.com • xeib.com • xueo.com -- Do not let others be treated this way! | ||
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |