Berkeley CSUA MOTD:Entry 41548
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2006/1/26-29 [Computer/SW/Languages/Web] UID:41548 Activity:nil
1/26    In PHP how do you do a regular http get? I'd like to avoid
        using system("wget ...") mechanism. Thanks.
        \_ $html = file_get_contents('<DEAD>...');<DEAD>    --dbushong
           For more details, read:
           http://php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen
           http://www.php.net/manual/en/features.remote-files.php
Cache (2887 bytes)
php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen -> www.php.net/manual/en/ref.filesystem.php
Filesystem Functions Introduction Requirements No external libraries are needed to build this extension, but if you want PHP to support LFS (large files) on Linux, then you need to have a recent glibc and you need compile PHP with the following compiler flags: -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64. Installation There is no installation needed to use these functions; Table 1 Filesystem and Streams Configuration Options Name Default Changeable Changelog allow_url_fopen "1" PHP_INI_SYSTEM PHP_INI_ALL in PHP <= 434 Available since PHP 404 user_agent NULL PHP_INI_ALL Available since PHP 430 default_socket_timeout "60" PHP_INI_ALL Available since PHP 430 from "" PHP_INI_ALL auto_detect_line_endings "0" PHP_INI_ALL Available since PHP 430 Here's a short explanation of the configuration directives. file() to see if it is using Unix, MS-Dos or Macintosh line-ending conventions. This enables PHP to interoperate with Macintosh systems, but defaults to Off, as there is a very small performance penalty when detecting the EOL conventions for the first line, and also because people using carriage-returns as item separators under Unix systems would experience non-backwards-compatible behaviour. When I have some free time (sooner rather than later), I'm going to write a more in-depth script for this. You can expect a PHP 4 and PHP 5 script class dedicated to this one idea. php function breadCrumbs($path) { /** * What it does is split a path string into its two base objects -- a * file name and a directory name. That finished string * is then returned to the calling script/function for display to the * browser. The main working function is get_dir($path,$max_depth='') Optional aguments: $max_depth : obvious it'll limit the recursive depth. Not so optional: $l=0 : the first call must omit this, or explicitly set it to 0, since it represents the starting depth $total='': the current total filesize; it should also be left alone, although it autosets itself to 0 on the first call; In order to do something with the files other than just echoing them, simply replace the echo functions with your own; And find out the maximum file size of given application files. for example it will tell the maximum file size of ppt file that is placed in the directory. function showExtension($file){ if(is_file($file)){ $fileInfo = pathinfo($file); Here's a little function to append a slash at the end of a path if there isn't one already. function append_slash_if_none($string) { if (ereg ("/$", $string)) { return $string; net contributed this in response to a question on setting these variables ... However, with PHP 50, stream_get_line() will allow you to specify what line ending character to read up to. mp3 or any other file that doesn't contain readable information. It makes use of the Character Type Extension if it's loaded, if it's not then it uses Regular Expressions.
Cache (1139 bytes)
www.php.net/manual/en/features.remote-files.php
For example, you can use this to open a file on a remote web server, parse the output for the data you want, and then use that data in a database query, or simply to output it in a style matching the rest of your website. It's part right because it's true that the php script will run on the remote server, if it's capable of interpreting php scripts. When you view it in a browser, you'll see the hostname of the remote machine. However, that does not mean there are no security worries here. So yes, remote includes can be a major security problem. Putting the 'b' in the second argument of fopen didn't help much, my browser still didn't want to display the images. I finally understood by watching the datas i was getting from the remote host: it was an html page ! hey, i didn't know apache sent html pages when requesting images, did you ? the right way is then to send an http request via fsockopen. Here comes my second problem, using explode("\n\n", $buffer); The right way is to get the value of the Content-Lenght field and use it in substr($buffer, -$Content-Lenght); php function http_get($url) { $url_stuff = parse_url($url);